<?php
/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	require(DIR_WS_CLASSES . 'currencies.php');
	require(DIR_WS_CLASSES . 'payment.php');
	$currencies = new currencies();
	include(DIR_WS_CLASSES . 'order.php');
	include(DIR_WS_CLASSES . 'ot_coupon.php');
		
	$command=isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'';
	$type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'B';

	$country=isset($HTTP_GET_VARS['country_id'])?(int)$HTTP_GET_VARS['country_id']:0;
	$qty=isset($HTTP_GET_VARS['qty'])?(int)$HTTP_GET_VARS['qty']:'0';
	$id=isset($HTTP_GET_VARS['id'])?(int)$HTTP_GET_VARS['id']:'';

//ajax start
	if($command!=""){
		if($command=='show_state'){
			$zone_ids="";
			$zone_name="";
			$zones_query = tep_db_query("select zone_id,zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country) . "' order by zone_name");
			while ($zones_values = tep_db_fetch_array($zones_query)) {
				$zone_ids.=$zones_values['zone_id'].",";
				$zone_name.=$zones_values['zone_name'].",";
			}
			$content='show_state'.substr($zone_ids,0,-1)."^".tep_output_string(substr($zone_name,0,-1))."^".$zone."^".$type;    
			echo $content;	   	   	   
		}else if($orders_id>0 && $orders_products_id>0){
			$value=isset($HTTP_GET_VARS['value'])?$HTTP_GET_VARS['value']:'';
			$orders_id=isset($HTTP_GET_VARS['orders_id'])?(int)$HTTP_GET_VARS['orders_id']:'0';
			$orders_products_id=isset($HTTP_GET_VARS['orders_products_id'])?(int)$HTTP_GET_VARS['orders_products_id']:'0';
			$attributes_id=isset($HTTP_GET_VARS['attributes_id'])?(int)$HTTP_GET_VARS['attributes_id']:'0';
			$pro_array=array();
			//$pro_array=array('P'=>'','E'=>'$update_event','S'=>'$update_subscription','V'=>'$update_service');
			//$update_product_qty=$update_product_tax=$update_product_uprice=$update_product_qty=$update_event_tax=$update_event_uprice=="";
			$updates=$update_attributes="";
			if($command=="update_qty"){
				if($value=='')$value=0;
				$updates=" set products_quantity='".$value."'";
			}else if($command=="update_tax"){
				if($value=='')$value=0;
				$updates=" set products_tax='".$value."'";
			}else if($command=="update_uprice"){
				if($value=='')$value=0;
				$updates=" set products_price='".$value."'";
			}else if($command=="update_name"){
				$updates = " set products_name='" . $value . "'";
			}else if($command=="update_attribute_name"){
				$update_attributes = " set products_options='" . $value . "'";
			}else if($command=="update_attribute_value"){
				$update_attributes = " set products_options_values='" . $value . "'";
			}
			if($type=='P' || $type=='S' || $type=="E" || $type=="V"){
				if($attributes_id>0){
					tep_db_query("update " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . $update_attributes . " where products_type='".$type."' and orders_id=" . (int)$orders_id . " and orders_products_id=" . (int)$orders_products_id . " and orders_products_attributes_id=" . (int)$attributes_id);
				}else{
					tep_db_query("update " . TABLE_ORDERS_EDIT_PRODUCTS . $updates . " where products_type='" . $type . "' and orders_products_id=" . (int)$orders_products_id);
				}
			}
			$orders_detail = new order($orders_id,true);
			$tax = 0;
			$subtotal = 0;
			$separate_tax = 0;
			$separate_subtotal = 0;
			for($i=0;$i<sizeof($orders_detail->products);$i++){
				if($orders_detail->products[$i]['orders_products_id']==$orders_products_id){
					$attribute_amount = 0;
					for($j=0;$j<sizeof($orders_detail->products[$i]['attributes']);$j++){
						if($orders_detail->products[$i]['attributes'][$j]['prefix']=="+")
							$attribute_amount += $orders_detail->products[$i]['attributes'][$j]['price'];
						else if($orders_detail->products[$i]['attributes'][$j]['prefix']=="-")
							$attribute_amount -= $orders_detail->products[$i]['attributes'][$j]['price'];
					}
					$separate_tax = (($orders_detail->products[$i]['tax'] / 100) * ($orders_detail->products[$i]['qty'] * ($orders_detail->products[$i]['price']+$attribute_amount)));
					$separate_subtotal = $currencies->format($separate_tax + (($orders_detail->products[$i]['final_price']+$attribute_amount) * $orders_detail->products[$i]['qty']), true, $orders_detail->info['currency'], $orders_detail->info['currency_value']);
					$val = $separate_tax + ($orders_detail->products[$i]['final_price']+$attribute_amount) * $orders_detail->products[$i]['qty'];
					tep_db_query("update " . TABLE_ORDERS_EDIT_PRODUCTS . " set final_price=" . $val . " where products_type='" . $type . "' and orders_products_id=" . (int)$orders_products_id);
				}
				$Tax = (($orders_detail->products[$i]['tax'] / 100) * ($orders_detail->products[$i]['qty'] * ($orders_detail->products[$i]['price']+$attribute_amount)));
				$tax += $Tax;
				$subtotal += $Tax + (($orders_detail->products[$i]['final_price']+$attribute_amount) * $orders_detail->products[$i]['qty']);
			}
			$tax = $currencies->format($tax, true, $orders_detail->info['currency'], $orders_detail->info['currency_value']);
			$subtotal = $currencies->format($subtotal, true, $orders_detail->info['currency'], $orders_detail->info['currency_value']);
			echo "order:" . $tax . ":" . $subtotal . ":" . $separate_subtotal . ":" . $orders_products_id;
		}		
		exit;
	}
	//ajax end
  $coupon_class=new ot_coupon;
  // New "Status History" table has different format.
  $OldNewStatusValues = (tep_field_exists(TABLE_ORDERS_STATUS_HISTORY, "old_value") && tep_field_exists(TABLE_ORDERS_STATUS_HISTORY, "new_value"));
  $CommentsWithStatus = tep_field_exists(TABLE_ORDERS_STATUS_HISTORY, "comments");
  $SeparateBillingFields = tep_field_exists(TABLE_ORDERS, "billing_name");
  $AddShippingTax = "0.0"; // e.g. shipping tax of 17.5% is "17.5"
 // echo "ediit";
  
  //break;

  // store all the status flags in an array
  $orders_statuses = array();
  $orders_status_array = array();
  $orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "'");
  while ($orders_status = tep_db_fetch_array($orders_status_query)) {
    $orders_statuses[] = array('id' => $orders_status['orders_status_id'],
                               'text' => $orders_status['orders_status_name']);
    $orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name'];
  }
  
  $oID=(isset($HTTP_GET_VARS['oID'])?(int)$HTTP_GET_VARS['oID']:0);
  $action=(isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:'');
  $step=(isset($HTTP_GET_VARS['step'])?(int)$HTTP_GET_VARS['step']:1);
  	       $edit_cart=new editOrderCart($oID);
		   

  if ((int)$oID<=0)
    tep_redirect(tep_href_link(FILENAME_ORDERS));

  if (!($step>=1 && $step<=4)){
    tep_redirect(tep_href_link(FILENAME_ORDERS));
  }

  // confirm order entry in the table before procedding
  $orders_query = tep_db_query("select orders_id,customers_id from " . TABLE_ORDERS . "  where orders_id = '" . (int)$oID . "'");
  $order_exists = true;
  if (!tep_db_num_rows($orders_query)) {
      $order_exists = false;
      $action="";
      //$messageStack->add_Session('orders',sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
      tep_redirect(tep_href_link(FILENAME_ORDERS));
  }
  $order_result=tep_db_fetch_array($orders_query);
  
  // check the order id with element in temporart edit cart and recreate the edit cart
  if (!tep_session_is_registered('edit_order') || $edit_order!=$oID){
          tep_session_unregister('edit_order');
	       $edit_cart=new editOrderCart($oID);
	       $edit_cart->restore_contents();
	       tep_session_register('edit_order');
	       $edit_order=$oID;
  } else {
     if (!tep_session_is_registered('edit_order'))
	   tep_redirect(tep_href_link(FILENAME_ORDERS));
  }
  $order_timestamp=time();
  if (!tep_session_is_registered('order_timestamp')) tep_session_register('order_timestamp');

  if (tep_not_null($action)) {
    switch ($action) {
		case 'delete_item':
			// delete the single item from edit cart 
			$id=(isset($HTTP_GET_VARS['id'])?$HTTP_GET_VARS['id']:'');
			$check_id="";
			// check for valid ids to work properly
			if ($id!=""){
				$id_splt=split(",",$id);
				for ($icnt=0;$icnt<count($id_splt);$icnt++){
					$id_splt[$icnt]=(int)$id_splt[$icnt];
				}
				$check_id=join(",",$id_splt);
			}
			if ($check_id!=""){
				tep_db_query("DELETE FROM " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_products_id in(" . $check_id . ")");
				tep_db_query("DELETE FROM " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " where orders_products_id in(" . $check_id .")");
				tep_db_query("DELETE FROM " . TABLE_ORDERS_EDIT_SERVICES . " where orders_id=' ".$oID." ' and orders_products_id in('" . $id . "')");
				tep_db_query("DELETE FROM " . TABLE_ORDERS_EDIT_SUBSCRIPTIONS . " where orders_id=' ".$oID." ' and orders_products_id in('" . $id . "')");
				
			}
			tep_redirect(tep_href_link(FILENAME_EDIT_ORDERS,'oID=' . $oID . '&step=2'));
			break;
		case 'delete_event':
			// delete the single item from edit cart 
			$id=(isset($HTTP_GET_VARS['id'])?(int)$HTTP_GET_VARS['id']:'');
			$id_types=(isset($HTTP_GET_VARS['id_types'])?$HTTP_GET_VARS['id_types']:'');
			$delete_string="";
			$check_id_group="";
			// check for valid ids to work properly
			if ($id!="" && $id_types!=""){
				$id_splt=split(",",$id);
				$id_types=split(",",$id_types);
				for ($icnt=0;$icnt<count($id_splt);$icnt++){
					if ($id_types[$icnt]=="g") {
						$check_id_group.=((int)$id_splt[$icnt]) . ",";
					} else {
						$delete_string.=((int)$id_splt[$icnt]) . ",";						
					}
				}
			}
			if ($check_id_group!=""){
				$check_id_group=substr($check_id_group,0,-1);
				$fetch_query=tep_db_query("SELECT op.orders_products_id from " . TABLE_ORDERS_EDIT_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS . " s where op.orders_id='" . (int)$oID . "' and s.events_id in(" . $check_id_group .") and op.products_id=s.sessions_id and op.products_type='E' and op.events_type='W'");
				while($fetch_result=tep_db_fetch_array($fetch_query))
					$delete_string.=$fetch_result["orders_products_id"] . ",";
			}
			if ($delete_string!="") {
				$delete_string=substr($delete_string,0,-1);
				tep_db_query("DELETE FROM " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_products_id in(" . $delete_string . ")");
				if (count($edit_cart->attendees)>0){
					$check_query=tep_db_query("SELECT count(*) as total from " . TABLE_ORDERS_EDIT_PRODUCTS . " where products_type='E' and products_quantity>1 and orders_id='" .(int)$oID . "'");
					$check_result=tep_db_fetch_array($check_query);
					if ($check_result["total"]<=0) $edit_cart->remove_attendees();
				}			
			}
			
			
			tep_redirect(tep_href_link(FILENAME_EDIT_ORDERS,'oID=' . $oID . '&step=2'));
			break;
	case 'update_order':
		// update the order contents
		$order = new order($oID);
		$status = tep_db_prepare_input($HTTP_POST_VARS['status']);
				
		// Update Order Info
		if(is_numeric($HTTP_POST_VARS['update_customer_country'])) $update_customer_country=tep_get_country_name($HTTP_POST_VARS['update_customer_country']); 
		if(is_numeric($HTTP_POST_VARS['update_billing_country'])) $update_billing_country=tep_get_country_name($HTTP_POST_VARS['update_billing_country']);
		if(is_numeric($HTTP_POST_VARS['update_delivery_country'])) $update_delivery_country=tep_get_country_name($HTTP_POST_VARS['update_delivery_country']);
		
		$update_delivery_name = tep_db_input($HTTP_POST_VARS['update_delivery_name']);	
		$update_delivery_company = tep_db_input($HTTP_POST_VARS['update_delivery_company']);
		$update_delivery_street_address=tep_db_input($HTTP_POST_VARS['update_delivery_street_address']);	
		$update_delivery_suburb=tep_db_input($HTTP_POST_VARS['update_delivery_suburb']);
		$update_delivery_city=tep_db_input($HTTP_POST_VARS['update_delivery_city']);
		$update_delivery_state=tep_db_input($HTTP_POST_VARS['update_delivery_state']);
		$update_delivery_postcode=tep_db_input($HTTP_POST_VARS['update_delivery_postcode']);
		$update_delivery_country=tep_db_input($HTTP_POST_VARS['update_delivery_country']);
		
		$update_customer_name=tep_db_input($HTTP_POST_VARS['update_customer_name']);
		$update_customer_city=tep_db_input($HTTP_POST_VARS['update_customer_city']);	
		$update_customer_state=tep_db_input($HTTP_POST_VARS['update_customer_state']);	
		$update_customer_postcode=tep_db_input($HTTP_POST_VARS['update_customer_postcode']);
		$update_customer_country=tep_db_input($HTTP_POST_VARS['update_customer_country']);	
		$update_customer_company=tep_db_input($HTTP_POST_VARS['update_customer_company']);	
		$update_customer_street_address=tep_db_input($HTTP_POST_VARS['update_customer_street_address']);	

		$update_customer_telephone=tep_db_input($HTTP_POST_VARS['update_customer_telephone']);
		$update_customer_second_telephone_number=tep_db_input($HTTP_POST_VARS['update_customer_second_telephone_number']);
		$update_customer_fax=tep_db_input($HTTP_POST_VARS['update_customer_fax']);	
		$update_customer_second_email_address=tep_db_input($HTTP_POST_VARS['update_customer_second_email_address']);
		$update_customer_email_address=tep_db_input($HTTP_POST_VARS['update_customer_email_address']);
		
		$update_billing_name=tep_db_input($HTTP_POST_VARS['update_billing_name']);
		$update_billing_company=tep_db_input($HTTP_POST_VARS['update_billing_company']);
		$update_billing_street_address=tep_db_input($HTTP_POST_VARS['update_billing_street_address']);
		$update_billing_suburb=tep_db_input($HTTP_POST_VARS['update_billing_suburb']);	
		$update_billing_city=tep_db_input($HTTP_POST_VARS['update_billing_city']);
		$update_billing_state=tep_db_input($HTTP_POST_VARS['update_billing_state']);
		$update_billing_postcode=tep_db_input($HTTP_POST_VARS['update_billing_postcode']);
		$update_billing_country=tep_db_input($HTTP_POST_VARS['update_billing_country']);
			
		
		
		if($HTTP_POST_VARS['update_billing_state1']!='')  $update_billing_state=$HTTP_POST_VARS['update_billing_state1']; 
		if($HTTP_POST_VARS['update_delivery_state1']!='')  $update_delivery_state=$HTTP_POST_VARS['update_delivery_state1'];
		if($HTTP_POST_VARS['update_customer_state1']!='')  $update_customer_state=$HTTP_POST_VARS['update_customer_state1'];
		if ($step==1){
		    $UpdateOrders = "update " . TABLE_ORDERS . " set ";
			$UpdateOrders .="customers_name = '" . tep_db_input(stripslashes($update_customer_name)) . "',
			customers_company = '" . tep_db_input(stripslashes($update_customer_company)) . "',
			customers_street_address = '" . tep_db_input(stripslashes($update_customer_street_address)) . "',
			customers_suburb = '" . tep_db_input(stripslashes($update_customer_suburb)) . "',
			customers_city = '" . tep_db_input(stripslashes($update_customer_city)) . "',
			customers_state = '" . tep_db_input(stripslashes($update_customer_state)) . "',
			customers_postcode = '" . tep_db_input(stripslashes($update_customer_postcode)) . "',
			customers_country = '" . tep_db_input(stripslashes($update_customer_country)) . "'";
		}
		// update billing and shipping details
		if ($step==3){
		  $UpdateOrders = "update " . TABLE_ORDERS . " set ";
		  if($SeparateBillingFields)
	   	   {
		      $UpdateOrders .= "billing_name = '" . tep_db_input(stripslashes($update_billing_name)) . "',
			billing_company = '" . tep_db_input(stripslashes($update_billing_company)) . "',
			billing_street_address = '" . tep_db_input(stripslashes($update_billing_street_address)) . "',
			billing_suburb = '" . tep_db_input(stripslashes($update_billing_suburb)) . "',
			billing_city = '" . tep_db_input(stripslashes($update_billing_city)) . "',
			billing_state = '" . tep_db_input(stripslashes($update_billing_state)) . "',
			billing_postcode = '" . tep_db_input(stripslashes($update_billing_postcode)) . "',
			billing_country = '" . tep_db_input(stripslashes($update_billing_country)) . "',";
		   }
		     $UpdateOrders .= " delivery_name = '" . tep_db_input(stripslashes($update_delivery_name)) . "',
			delivery_company = '" . tep_db_input(stripslashes($update_delivery_company)) . "',
			delivery_street_address = '" . tep_db_input(stripslashes($update_delivery_street_address)) . "',
			delivery_suburb = '" . tep_db_input(stripslashes($update_delivery_suburb)) . "',
			delivery_city = '" . tep_db_input(stripslashes($update_delivery_city)) . "',
			delivery_state = '" . tep_db_input(stripslashes($update_delivery_state)) . "',
			delivery_postcode = '" . tep_db_input(stripslashes($update_delivery_postcode)) . "',
			delivery_country = '" . tep_db_input(stripslashes($update_delivery_country)) . "',
			customers_telephone = '" . tep_db_input(stripslashes($update_customer_telephone)) . "',
		    customers_second_telephone = '" . tep_db_input(stripslashes($update_customer_second_telephone_number)) . "',
			customers_fax ='" . tep_db_input(stripslashes($update_customer_fax)) . "',
		    customers_second_email_address = '" . tep_db_input(stripslashes($update_customer_second_email_address)) . "',
			customers_email_address = '" . tep_db_input(stripslashes($update_customer_email_address)) . "'";
                }
        if ($UpdateOrders!=''){
 		   $UpdateOrders .= " where orders_id = '" . tep_db_prepare_input($oID) . "';";
		   tep_db_query($UpdateOrders);
		}
		if ($step==2 && sizeof($update_products)>0){
		// Update Products and event items
		   $product_type=isset($HTTP_POST_VARS['products_type'])?$HTTP_POST_VARS['products_type']:'';
		   foreach($update_products as $orders_products_id => $products_details)
		   {
			// Update orders_products Table
			if($products_details["qty"] > 0)
			{
			   if(tep_convert_date_raw($products_details["model"])) $products_details["model"]=tep_convert_date_raw(tep_db_input(stripslashes($products_details["model"])));
				$Query = "update " . TABLE_ORDERS_EDIT_PRODUCTS . " set
					products_model = '" . tep_db_input(stripslashes($products_details["model"])) . "',
					products_name = '" . tep_db_input(stripslashes($products_details["name"])) . "',
					final_price = '" . tep_db_input($products_details["final_price"]) . "',
					products_tax = '" . tep_db_input($products_details["tax"]) . "',
					products_quantity = '" . tep_db_input($products_details["qty"]) . "'
					where orders_products_id = '$orders_products_id';";
				tep_db_query($Query);
                       	
				// Update Any Attributes
				if(IsSet($products_details[attributes]))
				{
					foreach($products_details["attributes"] as $orders_products_attributes_id => $attributes_details)
					{
						$Query = "update " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " set
							products_options = '" . tep_db_input(stripslashes($attributes_details["option"])) . "',
							products_options_values = '" . tep_db_input($attributes_details["value"]) . "'
							where orders_products_attributes_id = '$orders_products_attributes_id';";
						tep_db_query($Query);
					}
				}
			}
			else
			{
				// 0 Quantity = Delete
				$Query = "delete from " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_products_id = '$orders_products_id';";
				tep_db_query($Query);
				$Query = "delete from " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " where orders_products_id = '$orders_products_id';";
				tep_db_query($Query);
			}
		   }
		 }
		if (USE_CACHE == 'true') {
		    tep_reset_cache_block(TABLE_EDIT_ORDERS_PRODUCTS_ATTRIBUTES);
		    tep_reset_cache_block(TABLE_EDIT_ORDERS_PRODUCTS);
		    tep_reset_cache_block(TABLE_ORDERS);
		}
		   if ($step>=4){
		   tep_redirect(tep_href_link("orders.php", 'oID=' . $oID . '&page=1&action=edit'));}
		else
		{
		  if ($step==2){
		    if ($product_type=="E") tep_redirect(tep_href_link(FILENAME_EDIT_ORDERS,'oID=' . $oID . '&step=4&type=' . $product_type));
		  }
		  $step=$step+1;
		  tep_redirect(tep_href_link(FILENAME_EDIT_ORDERS, 'oID=' . $oID . '&step=' . $step . '&type=' . $product_type));
		}  
	break;
    }
  }

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">
 	function update_values(oid,products_id,attributes_id,ths,str_update){
		command="<?php echo tep_href_link(FILENAME_EDIT_ORDERS);?>?command="+str_update+"&orders_id="+oid+"&orders_products_id="+products_id+"&attributes_id="+attributes_id+ths;
 		setTimeout('do_get_command(command)',2000); 		 		 		
 		clearTimeout();	
 	} 	
	/*function show_state(do_this){
		var this_=do_this;
		id=this_.options[this_.selectedIndex].value;
		type=(this_.name.indexOf('billing')>0)?'B':((this_.name.indexOf('customer')>0)?'C':'D');
		if(id){
			command="<?php echo tep_href_link(FILENAME_EDIT_ORDERS,'command=show_state');?>&country_id="+id+"&type="+type;
			do_get_command(command);
			if(do_this.name.indexOf('billing')>0) document.getElementById("update_billing_state").innerHTML="Loading...";
			else if(do_this.name.indexOf('delivery')>0) document.getElementById("update_delivery_state").innerHTML="Loading...";
		}else{
			if(do_this.name.indexOf('billing')>0) document.getElementById("update_billing_state").innerHTML="";
			else if(do_this.name.indexOf('delivery')>0) document.getElementById("update_delivery_state").innerHTML="";
		}
	}*/
	function show_state(do_this){ 
		var this_=do_this;
		id=this_.options[this_.selectedIndex].value;
		type=(this_.name.indexOf('billing')>0)?'B':((this_.name.indexOf('customer')>0)?'C':'D');
		if(id){
			command="<?php echo tep_href_link(FILENAME_EDIT_ORDERS,'command=show_state');?>&country_id="+id+"&type="+type;
			do_get_command(command);
			if(do_this.name.indexOf('billing')>0) document.getElementById("update_billing_state").innerHTML="Loading...";
			else if(do_this.name.indexOf('delivery')>0) document.getElementById("update_delivery_state").innerHTML="Loading...";
		}else{
			if(do_this.name.indexOf('billing')>0) document.getElementById("update_billing_state").innerHTML="Loading...";
			else if(do_this.name.indexOf('delivery')>0) document.getElementById("update_delivery_state").innerHTML="Loading...";
		}
	}
	function do_result(result){
		if(result!='' && result.substr(result.indexOf('show_state'),10)=='show_state'){
			result=result.substr(result.indexOf('show_state')+10,result.length);
			var textArr=new Array();
			var valueArr=new Array();
			splt=result.split("^");
			valueArr=splt[1].split(",");		
			textArr=splt[1].split(",");
			sel_zone=splt[2];
			type=splt[3];
			if(type=='B' && document.getElementById("update_billing_state")) var sel=document.getElementById("update_billing_state");
			else if(type=='D' &&  document.getElementById("update_delivery_state")) var sel=document.getElementById("update_delivery_state");
			else if(type=='C' &&  document.getElementById("update_customer_state")) var sel=document.getElementById("update_customer_state");
			if(type=='B' &&  document.getElementById("update_billing_state1")) state1=document.getElementById("update_billing_state1");
			else if(type=='D' &&  document.getElementById("update_delivery_state1")) state1=document.getElementById("update_delivery_state1");
			else if(type=='C' &&  document.getElementById("update_customer_state1")) state1=document.getElementById("update_customer_state1");
			if(valueArr.length==1) {
				if(state1) state1.style.display="";
				if(sel)	sel.style.display="none";
			}else if(valueArr.length>1){
				if(state1){
					state1.value="";
					state1.style.display="none";
				} 
				sel.style.display="";
				optionElement=sel;
				// clear the previous details
				while(optionElement.options.length>0){
					optionElement.remove(optionElement.options.length - 1);
				}
				//create the new details
				for (icnt=0;icnt<textArr.length;icnt++){
				  var option = document.createElement('option');
				  option.text = textArr[icnt];
				  option.value = valueArr[icnt];
				  try {
					optionElement.add(option, null); // standards compliant; doesn't work in IE
				  }
				  catch(ex) {
					optionElement.add(option); // IE only
				  }
			}
			if(typeof(default_zone) != "undefined")
			for(i=0;i<optionElement.options.length;i++){
				if(optionElement.options[i].value==default_zone)
					optionElement.options[i].selected = true;
			}
			if(document.getElementById("state1") && typeof(default_country) != "undefined")
			if(default_country!=document.getElementById("country"))
				document.getElementById("state1").value="";
		}
	  }else if(result!='' && result.indexOf(":")>0){
	  	result = result.split(":");
		document.getElementById("u_st").innerHTML = result[2];
		document.getElementById("u_tl").innerHTML = result[2];
		document.getElementById("u_tx").innerHTML = result[1];
		document.getElementById("total_"+result[4]).innerHTML = result[3];
	  }
	}
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php
	include('includes/date_format_js.php');
  require(DIR_WS_INCLUDES . 'header.php');
?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<script language="javascript">    
   function validateForm(){
      var error_result="";
      var select_payment=0;
<?php if($step==1) { ?>
	if(document.edit_order.update_customer_name)
      if (document.edit_order.update_customer_name.value=="")
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_NAME); ?>";
      else if (document.edit_order.update_customer_street_address.value=="")
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_ADDRESS); ?>";
      else if (document.edit_order.update_customer_suburb.value=="")
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_SUBURB); ?>";
      else if (document.edit_order.update_customer_city.value=="")
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_CITY); ?>";
      else if ((document.edit_order.update_customer_state.style.display!='none' && document.edit_order.update_customer_state.value=="") || (document.edit_order.update_customer_state1.style.display!='none' && document.edit_order.update_customer_state1.value==""))
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_STATE); ?>";
      else if (document.edit_order.update_customer_postcode.value=="")
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_POSTCODE); ?>";
      else if (document.edit_order.update_customer_country.value=="")
         error_result="<?php echo tep_db_input(ERR_CUSTOMER . ERR_COUNTRY); ?>";
<?php } 
      if($step==12) {?>
        if (document.edit_order.products_check.value!="valid")
         error_result="<?php echo tep_db_input(ERR_SELECT_PRODUCTS); ?>";
<?php } 
  if ($step==3){
   if($SeparateBillingFields) { ?>
      if (document.edit_order.update_billing_name.value=="")
         error_result="<?php echo tep_db_input(ERR_BILLING . ERR_NAME); ?>";
      else if (document.edit_order.update_billing_street_address.value=="")
         error_result="<?php echo tep_db_input(ERR_BILLING . ERR_ADDRESS); ?>";
      else if (document.edit_order.update_billing_city.value=="")
         error_result="<?php echo tep_db_input(ERR_BILLING . ERR_CITY); ?>";
      else if ((document.edit_order.update_billing_state.style.display!='none' && document.edit_order.update_billing_state.value=="")||(document.edit_order.update_billing_state1.style.display!='none' && document.edit_order.update_billing_state1.value==""))
         error_result="<?php echo tep_db_input(ERR_BILLING . ERR_STATE); ?>";
      else if (document.edit_order.update_billing_postcode && document.edit_order.update_billing_postcode.value=="")
         error_result="<?php echo tep_db_input(ERR_BILLING . ERR_POSTCODE); ?>";
      else if (document.edit_order.update_billing_country.value=="")
         error_result="<?php echo tep_db_input(ERR_BILLING . ERR_COUNTRY); ?>";
<?php } ?>
     if (error_result==""){
      if (document.edit_order.update_delivery_name.value=="")
         error_result="<?php echo tep_db_input(ERR_DELIVERY . ERR_NAME); ?>";
      else if (document.edit_order.update_delivery_street_address.value=="")
         error_result="<?php echo tep_db_input(ERR_DELIVERY . ERR_ADDRESS); ?>";
      else if (document.edit_order.update_delivery_city.value=="")
         error_result="<?php echo tep_db_input(ERR_DELIVERY . ERR_CITY); ?>";
      else if ((document.edit_order.update_delivery_state.style.display!='none' && document.edit_order.update_delivery_state.value=="")|| (document.edit_order.update_delivery_state1.style.display!='none' && document.edit_order.update_delivery_state1.value==""))
         error_result="<?php echo tep_db_input(ERR_DELIVERY . ERR_STATE); ?>";
      else if (document.edit_order.update_delivery_postcode.value=="")
         error_result="<?php echo tep_db_input(ERR_DELIVERY . ERR_POSTCODE); ?>";
      else if (document.edit_order.update_delivery_country.value=="")
         error_result="<?php echo tep_db_input(ERR_DELIVERY . ERR_COUNTRY); ?>";
      else if (document.edit_order.update_customer_telephone.value=="")
         error_result="<?php echo tep_db_input(ERR_TELEPHONE_NUMBER); ?>";
      else if (document.edit_order.update_customer_email_address.value.indexOf("@")==-1 || document.edit_order.update_customer_email_address.value.indexOf(".")==-1)
         error_result="<?php echo tep_db_input(ERR_EMAIL_ADDRESS); ?>";
      else if (document.edit_order.update_customer_second_email_address.value!="" && (document.edit_order.update_customer_second_email_address.value.indexOf("@")==-1 || document.edit_order.update_customer_second_email_address.value.indexOf(".")==-1))
     		error_result="<?php echo tep_db_input(ENTRY_SECOND_EMAIL_ADDRESS_CHECK_ERROR); ?>";	
          
     }
<?php } ?>
      if (error_result!=""){
         alert(error_result); 
	 	 return false;
	 }
      return true;
   }


</script>
<?php
  if ($order_exists == true && $action=='') {
    $order_detail = new order($oID);
switch ($step)
{
	case 2:
		$disp_title=HEADING_ITEMS;
		break;
	case 3:
		$disp_title=HEADING_SHIPPING;
		break;
	case 4:
		$disp_title=HEADING_PAYMENT;
		break;
	default:
		$disp_title=HEADING_ITEMS;
		break;
}
?>

      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <!--<td class="pageHeading"><font class=pageheading_alt><?php //echo HEADING_CREATE_ORDER; ?> > </font><font class=pageheading><?php echo $disp_title; ?></font></td>!-->
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td class="pageHeading" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ORDERS, 'oID=' . $oID . '&action=edit') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
          </tr>
        </table></td>
      </tr>
		<tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td><font class=main><b><?php echo TEXT_CUSTOMER; ?></b></font><font class="contentTitle" size="+6"><?php echo $order_detail->customer['name']; ?></font></td>
           <!-- <td  align="right"><?php //echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>!-->
          </tr>
        </table></td>
	  <tr>
	  	
	  </tr>
<!-- Begin Addresses Block -->

  <?php 
  // set action depend on step value
  if ($step==4) {?>
  
      <tr><?php echo tep_draw_form('edit_order', FILENAME_EDIT_ORDERS_CONFIRM, 'oID=' . $oID,'post','onSubmit="return validateForm()"'); ?>
  <?php } else {?>
      <tr><?php echo tep_draw_form('edit_order', FILENAME_EDIT_ORDERS, 'oID=' . $oID  . '&action=update_order&step=' . $step,'post','onSubmit="return validateForm()"'); ?>  
  <?php } ?>
	<td valign=top><table width="100%" border="0" cellspacing="0" cellpadding="2">

<?php if ($step==1){ ?>
	  <!--<tr>
	    <td colspan="2" class=infoBoxHeading><?php echo tep_draw_separator('pixel_trans.gif','1','3'); ?></td>
	  </tr>!-->
	  <tr>
	    <td valign="top">
		<table border="0" cellspacing="2" cellpadding="2"  width=60%>
		<tr>
		    <td class="main" width=30%><?php echo TEXT_NAME; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_name',tep_html_quotes($order_detail->customer['name']),'size=37',true); ?></td>
		</tr>
		<tr>
		    <td class="main" width=30%><?php echo TEXT_COMPANY; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_company',tep_html_quotes($order_detail->customer['company']),'size=37'); ?></td>
		</tr>
		<tr>
		    <td class="main"><?php echo TEXT_ADDRESS; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_street_address',tep_html_quotes($order_detail->customer['street_address']),'size=37',true); ?></td>
		</tr>
		<tr>
		    <td class="main"><?php echo TEXT_SUBURB; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_suburb',tep_html_quotes($order_detail->customer['suburb']),'size=37',true); ?></td>
		</tr>
		<tr>
		    <td class="main"><?php echo TEXT_POSTCODE; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_postcode',tep_html_quotes($order_detail->customer['postcode']),'size=37',true); ?></td>
		</tr>
		<tr>
		    <td class="main"><?php echo TEXT_CITY; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_city',tep_html_quotes($order_detail->customer['city']),'size=37',true); ?></td>
		</tr>
		<tr>
		    <td class="main"><?php echo TEXT_COUNTRY; ?></td>
		    <td class="main"><?php 
		    $country_id=tep_get_country_id(tep_html_quotes($order_detail->billing['country']));
		    echo sbs_get_country_list('update_customer_country', $country_id,'id="update_customer_country" onchange="javascript:show_state(this);"');
		    // echo tep_draw_input_field('update_billing_country',tep_html_quotes($order_detail->billing['country']),'size=37 id="update_billing_country" onchange="javascript:show_state();"',true); ?></td>
		</tr>
		<tr>
		    <td class="main"><?php echo TEXT_STATE; ?></td>
		    <td class="main"><?php 
		    $state=tep_html_quotes($order_detail->billing['state']);
		    //$zone_id=tep_get_zone_id($country_id,$state);
		    $zones_array = array(); 
          	$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country_id) . "' order by zone_name");
          	while ($zones_values = tep_db_fetch_array($zones_query)) {
	           $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
          	}
          	$sty_txt='';
          	$sty_combo='style="display:none"';
          	if(count($zones_array)>0){
          		$sty_combo='';
          		$sty_txt='style="display:none"';
          	}
		    echo tep_draw_input_field('update_customer_state1',$state,'size=37 '.$sty_txt);
    		echo tep_draw_pull_down_menu('update_customer_state',$zones_array,$state,$sty_combo);
		    //echo tep_draw_input_field('update_billing_state',tep_html_quotes($order_detail->billing['state']),'size=37',true); ?></td>
		</tr>
		</table>
	    </td>
	    </tr>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','5'); ?></td>
	  </tr>
<?php } ?>
<?php if ($step==3){ ?>
	<!--<tr>
		<td class=infoBoxHeading><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	</tr>!-->

       <?php if($SeparateBillingFields) { ?>
   		<?php tep_content_title_top(ENTRY_CUSTOMER_ADDRESS); ?>
	  <!--<tr>
	    <td colspan="2"><?php //echo tep_draw_separator('pixel_trans.gif','1','5'); ?></td>
	  </tr>!-->
	  <tr>






	    <td valign="top">
	    <!-- Billing Address Block -->
		<table border="0" cellspacing="1" cellpadding="2"  width=60%>
		<tr>
		    <td class="main" width="30%"><?php echo TEXT_NAME; ?></td>
		    <td class="main" nowrap="nowrap"><?php echo tep_draw_input_field('update_billing_name',tep_html_quotes($order_detail->billing['name']),'size=25',true); ?></td>
			<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo TEXT_ADDRESS; ?></td>
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo tep_draw_input_field('update_billing_street_address',tep_html_quotes($order_detail->billing['street_address']),'size=25',true); ?></td>
		</tr>
		<tr>
		<?php
 			 if (ACCOUNT_COMPANY == 'true') {
		?>
		    <td class="main"><?php echo TEXT_COMPANY; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_billing_company',tep_html_quotes($order_detail->billing['company']),'size=25'); ?></td>
		<?php } else { ?>	
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td>
		<?php } ?>
		<?php 
		  if (ACCOUNT_SUBURB == 'true') {
		?>
			<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo TEXT_SUBURB; ?></td>
		    <td class="main">&nbsp;&nbsp;&nbsp;<?php echo tep_draw_input_field('update_billing_suburb',tep_html_quotes($order_detail->billing['suburb']),'size=25'); ?></td>
		<?php } else { ?>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td>
		<?php }?>		
		</tr>
		<tr>
      		  <td class="main" width="30%" nowrap><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>
     		  <td class="main" nowrap="nowrap"><?php echo tep_draw_input_field('update_customer_telephone',$order_detail->customer['telephone'],'size=25',true); ?></td>
        	  <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo TEXT_CITY; ?></td>
		      <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo tep_draw_input_field('update_billing_city',tep_html_quotes($order_detail->billing['city']),'size=25',true); ?></td>
		</tr>
		<tr><?php if (ACCOUNT_SECOND_PHONE=='true') { ?>
		    <td class="main" nowrap><?php echo TEXT_SECOND_TELEPHONE; ?></td>
		    <td class="main" nowrap="nowrap"><?php echo tep_draw_input_field('update_customer_second_telephone_number',tep_html_quotes($order_detail->customer['second_telephone']),'size=25'); ?></td>
		 	<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo TEXT_POSTCODE; ?></td>
		    <td class="main" nowrap>&nbsp;&nbsp;&nbsp;<?php echo tep_draw_input_field('update_billing_postcode',tep_html_quotes($order_detail->billing['postcode']),'size=25',true); ?></td>
		  <?php } ?>
		 </tr>
		 <tr>
		    <td class="main"><?php echo TEXT_MOBILE; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_customer_fax',tep_html_quotes($order_detail->customer['fax']),'size=25'); ?></td>
			
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo TEXT_COUNTRY; ?></td>
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php
		    $country_id=tep_get_country_id(tep_html_quotes($order_detail->billing['country']));
		    echo sbs_get_country_list('update_billing_country', $country_id,'id="update_billing_country"  onchange="javascript:show_state(this);"');
		    // echo tep_draw_input_field('update_billing_country',tep_html_quotes($order_detail->billing['country']),'size=37 id="update_billing_country" onchange="javascript:show_state();"',true); ?></td>
		</tr>
		<tr>
		  <td class="main"><?php echo ENTRY_EMAIL_ADDRESS; ?></td>
		  <td class="main" nowrap><?php echo tep_draw_input_field('update_customer_email_address',$order_detail->customer['email_address'],'size=25',true); ?></td>
		  <?php
  					if (ACCOUNT_STATE == 'true') {
		?>
			<td class="main" nowrap="nowrap">&nbsp;&nbsp;<?php echo TEXT_STATE; ?></td>
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php 
		    $state=tep_html_quotes($order_detail->billing['state']);
		    //$zone_id=tep_get_zone_id($country_id,$state);
		    $zones_array = array(); 
          	$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country_id) . "' order by zone_name");
          	while ($zones_values = tep_db_fetch_array($zones_query)) {
	           $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
          	}
          	$sty_txt="";
          	$sty_combo='style="display:none"';
          	if(count($zones_array)>0){
          		$sty_combo='';
          		$sty_txt='style="display:none"';
          	}
		    echo tep_draw_input_field('update_billing_state1',$state,'size=25 '.$sty_txt);
    		echo tep_draw_pull_down_menu('update_billing_state', $zones_array,$state,$sty_combo);
		    //echo tep_draw_input_field('update_billing_state',tep_html_quotes($order_detail->billing['state']),'size=37',true); ?></td>
		<?php } else {?>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td>
		<?php }?>	
		</tr>
		<tr>  
	  <?php if (ACCOUNT_SECOND_EMAIL=='true') { ?>
			 <td class="main" nowrap><?php echo TEXT_SECOND_EMAIL; ?></td>
			 <td class="main" nowrap="nowrap"><?php echo tep_draw_input_field('update_customer_second_email_address',tep_html_quotes($order_detail->customer['second_email_address']),'size=25'); ?></td>
	   <?php } ?>
	   </tr>
	  </table>
	 </td>
	</tr>  
	<?php tep_content_title_bottom(); ?>
<?php  } ?>
		
   		
	 <?php tep_content_title_top(ENTRY_SHIPPING_ADDRESS); ?>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','3'); ?></td>
	  </tr>
	  <tr>
		<td valign="top">
	   <!-- Shipping Address Block -->
		<table border="0" cellspacing="1" cellpadding="2"  width=60%>
		<tr>
		    <td class="main" width="30%"><?php echo TEXT_NAME; ?></td>
		    <td class="main" nowrap="nowrap">
				<?php echo tep_draw_separator('pixel_trans.gif', 82, 10);
				 echo tep_draw_input_field('update_delivery_name',tep_html_quotes($order_detail->delivery['name']),'size=25',true); ?>
			</td>
			<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo TEXT_CITY; ?></td>
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;
			<?php echo tep_draw_input_field('update_delivery_city',tep_html_quotes($order_detail->delivery['city']),'size=25',true); ?></td>
       </tr>
	<?php
	  if (ACCOUNT_COMPANY == 'true') {
	?>		<tr>
		    <td class="main" nowrap="nowrap"><?php echo TEXT_COMPANY; ?></td>
		    <td class="main" nowrap="nowrap">
				<?php  echo tep_draw_separator('pixel_trans.gif', 82, 10);
				echo tep_draw_input_field('update_delivery_company',tep_html_quotes($order_detail->delivery['company']),'size=25'); ?></td>
			<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo TEXT_POSTCODE; ?></td>
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo tep_draw_input_field('update_delivery_postcode',tep_html_quotes($order_detail->delivery['postcode']),'size=25',true); ?></td>
		</tr>
<?php } ?>
		<tr>
		    <td class="main" nowrap="nowrap"><?php echo TEXT_ADDRESS; ?></td>
		    <td class="main" nowrap="nowrap">
				<?php echo tep_draw_separator('pixel_trans.gif',82, 10);
				 echo tep_draw_input_field('update_delivery_street_address',tep_html_quotes($order_detail->delivery['street_address']),'size=25',true); ?></td>
			<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo TEXT_COUNTRY; ?></td>
		    <td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php 
		    $country_id=tep_get_country_id(tep_html_quotes($order_detail->delivery['country']));
		    echo sbs_get_country_list('update_delivery_country', $country_id,'id="update_delivery_country" onchange="javascript:show_state(this);"');
		    //echo tep_draw_input_field('update_delivery_country',tep_html_quotes($order_detail->delivery['country']),'size=37',true); ?></td>
		</tr>
	<tr>	
	<td class="main" nowrap="nowrap">
<?php 
  if (ACCOUNT_SUBURB == 'true') {
?>		
		   <!-- <td class="main" nowrap="nowrap"> !--><?php echo TEXT_SUBURB; ?></td>
		    <td class="main" nowrap="nowrap">
			   <?php echo tep_draw_separator('pixel_trans.gif', 82, 10);
			    echo tep_draw_input_field('update_delivery_suburb',tep_html_quotes($order_detail->delivery['suburb']),'size=25'); ?>
			</td>
	
	<?php }
	else { ?>
			<td colspan="1"><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td>
		<?php }?> 
   <?php
     if (ACCOUNT_STATE == 'true') { 
   ?>	<!--	<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp; !--> 
   			<td class="main" nowrap="nowrap">&nbsp;&nbsp;&nbsp;<?php echo TEXT_STATE; ?></td>
		    <td class="main" nowrap="nowrap" align="left">&nbsp;&nbsp;&nbsp;<?php 
		    $state=tep_html_quotes($order_detail->delivery['state']);
		    //$zone_id=tep_get_zone_id($country_id,$state);
		    $zones_array = array(); 
          	$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country_id) . "' order by zone_name");
          	while ($zones_values = tep_db_fetch_array($zones_query)) {
	           $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
          	}
 			$sty_txt="";
          	$sty_combo='style="display:none"';
          	if(count($zones_array)>0){
          		$sty_combo='';
          		$sty_txt='style="display:none"';
          	}
			//echo tep_draw_separator('pixel_trans.gif', 47, 10);			
			echo tep_draw_input_field('update_delivery_state1',$state,'size=37 '.$sty_txt);
    		echo tep_draw_pull_down_menu('update_delivery_state',$zones_array,$state,$sty_combo);
		    ?></td>
	<?php } ?>	
	  </tr>
		<!--<tr>
		    <td class="main"><?php echo TEXT_CITY; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_delivery_city',tep_html_quotes($order_detail->delivery['city']),'size=25',true); ?></td>
		</tr>!-->
		<!--<tr>
		    <td class="main"><?php echo TEXT_POSTCODE; ?></td>
		    <td class="main"><?php echo tep_draw_input_field('update_delivery_postcode',tep_html_quotes($order_detail->delivery['postcode']),'size=25',true); ?></td>
		</tr>!-->
	<!--<tr>
		    <td class="main"><?php echo TEXT_COUNTRY; ?></td>
		    <td class="main"><?php 
		    //$country_id=tep_get_country_id(tep_html_quotes($order_detail->delivery['country']));
		    //echo sbs_get_country_list('update_delivery_country', $country_id,'id="update_delivery_country" onchange="javascript:show_state(this);"');
		    //echo tep_draw_input_field('update_delivery_country',tep_html_quotes($order_detail->delivery['country']),'size=37',true); ?></td>
		</tr>!-->
<?php
 // if (ACCOUNT_STATE == 'true') {
?>		<!--<tr>
		    <td class="main"><?php //echo TEXT_STATE; ?></td>
		    <td class="main"><?php 
		    /*$state=tep_html_quotes($order_detail->delivery['state']);
		    //$zone_id=tep_get_zone_id($country_id,$state);
		    $zones_array = array(); 
          	$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($country_id) . "' order by zone_name");
          	while ($zones_values = tep_db_fetch_array($zones_query)) {
	           $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
          	}
 			$sty_txt="";
          	$sty_combo='style="display:none"';
          	if(count($zones_array)>0){
          		$sty_combo='';
          		$sty_txt='style="display:none"';
          	}
		    echo tep_draw_input_field('update_delivery_state1',$state,'size=37 '.$sty_txt);
    		echo tep_draw_pull_down_menu('update_delivery_state',$zones_array,$state,$sty_combo);
		    ?></td>
		</tr>
	<?php } */ ?>	
		</table>
	    </td>
	  </tr>!-->
	  <tr height="10"></tr>
    <?php tep_content_title_bottom(); ?>
	<tr>
		<td class="contentTitle" height="1px"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	</tr>
	</table></td>
      </tr><!-- End Addresses Block -->
<?php } ?>
<?php if ($step==4) {
	  $order=new order($oID,true);
    tep_session_unregister('payment');
      $tax=0.0;
	   $updated_subtotal=0.0;
		$updated_tax=0.0;
		$updated_total=0.0;
		$present_total=0.0;
		$net_amount=0.0;
		$orders_products_query = tep_db_query("select * from " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_id = '" . (int)$oID . "'");
		 while ($orders_products = tep_db_fetch_array($orders_products_query)) {
		  $tax = (($orders_products['products_tax'] / 100) * (($orders_products['products_quantity'] * $orders_products['final_price'])));
  		  $updated_subtotal += ((($orders_products['products_quantity'] * $orders_products['final_price']))+$tax);
		  $updated_tax+=$tax;
         }
		$updated_total=$updated_subtotal; 
		$totals_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$oID . "' and class='ot_total'");        
        $totals=tep_db_fetch_array($totals_query);
		if (isset($totals['value'])) $present_total=$totals['value'];
		$amount_diff=$updated_total-$present_total;  		
		$payment_query=tep_db_query("select payment_method from " . TABLE_ORDERS . " where orders_id= '" . (int)$oID . "'");
		$payment_result=tep_db_fetch_array($payment_query);
		$payment_method='';
		$net_amount=0;
		if (isset($payment_result['payment_method']))
		  $payment_method=$payment_result['payment_method'];
		if ($payment_method=='Cash' || $payment_method=='Credit Card'){
		  if($amount_diff<0){
		   $pay_type='refund';
		   $display_title='admin';
		   $net_amount=$amount_diff;
		  }else if ($amount_diff>0){
		   $display_title='customer';
		   $pay_type='getamount';
		   $net_amount=$updated_total-$present_total;}
		} else if ($payment_method=='change'){
         $net_amount=$present_total;
		   $display_title='customer';
		} else {
		  if ($amount_diff>0 || $amount_diff<=0){
		    if ($updated_total>0){
		       $net_amount=$updated_total;
		       $display_title='customer';
		    }
		    else
		    {
		       $display_title='admin';
		       $net_amount=$present_total;
		    }
		  }
		}
		if ($net_amount==0) 
		   $pay_type='Nil';
		else
	  	   $pay_type='getamount';
   $payment_modules=new payment();
   	$net_amount=tep_get_rounded_amount($net_amount);
	$update_details=false;
	if ($updated_total>0 && strval($updated_total)==strval($present_total)) $update_details=true;
	$items=array();
	
?>
<table border="0" width="50%" cellspacing="0" cellpadding="2" class="dataTablerowover">
	<?php 
		for ($i=0, $n=count($order->products); $i<$n; $i++) {
			switch($order->products[$i]['products_type'])
			{
				case 'P':
					$index=0;
					break;
				case 'S':
					$index=2;
					break;
				case 'E':
					$index=1;
					break;
				case 'V':
					$index=3;
					break;
			}
			$items[$index].='<tr>' . "\n" .
			'            <td class="main_item" width="70%"  valign="top">' . $order->products[$i]['name'] ;

			if ($order->products[$i]['products_type']=="V"){
				if($order->products[$i]['others']['end_date'] && $order->products[$i]['others']['end_time']){	
					$str_time=strtotime($order->products[$i]['others']['end_date'] .' '.$order->products[$i]['others']['end_time'])+60;
					$order->products[$i]['others']['end_date']=date('Y-m-d',$str_time);
					$order->products[$i]['others']['end_time']=date('H:i:s',$str_time); 
				}
				if($order->products[$i]['others']['resource_id']!='') $resource_costs=tep_add_tax(tep_get_resource('resource_costs',$order->products[$i]['others']['resource_id'],$languages_id),$order->products[$i]['tax']);
				$items[$index].='<br><small><i>&nbsp;	- '.TEXT_START_DATE.' : '. format_date($order->products[$i]['others']['start_date']) . '&nbsp;' . (($order->products[$i]['others']['start_time'])?date("h:i A",strtotime($order->products[$i]['others']['start_time'])):'') . ' <br>&nbsp; - ' . TEXT_END_DATE .' : ' . format_date($order->products[$i]['others']['end_date']). '&nbsp;' . (($order->products[$i]['others']['end_time'])?date("h:i A",strtotime($order->products[$i]['others']['end_time'])):'') . ' '.(($order->products[$i]['others']['resource_id'])? '<br>&nbsp; - '.tep_get_resource_name($order->products[$i]['others']['resource_id'],'resource_name').'('.$currencies->format($resource_costs).')':'').'</i></small>';																			
			} 
			if (isset($order->products[$i]['attributes']) && is_array($order->products[$i]['attributes'])) {
				reset($order->products[$i]['attributes']);
				$attribute_id="";
				for($k=0,$att_max=sizeof($order->products[$i]['attributes']);$k<$att_max;$k++) {
					$att_row=$order->products[$i]['attributes'][$k];
					if($attribute_id!="")
						$attribute_id.="-";
					$attribute_id.=$att_row['option_id'] . "{" . $att_row['value_id'] . "}";
				}
				for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
					if($order->products[$i]['attributes'][$j]['option'] && $order->products[$i]['attributes'][$j]['value'])  $items[$index].= '<br><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '('.$currencies->format(tep_add_tax($order->products[$i]['attributes'][$j]['price'],$order->products[$i]['tax'])).')</i></small></nobr>';
				}
			}
			$disp_total+=$order->products[$i]['final_price'];
			$items[$index].='</td>' . "\n" . '<td class="main_item" align="center" valign="top" width="10%">' . $order->products[$i]['qty'] .' </td>' . "\n" ;
			$items[$index].= '<td class="main_item" align="right" valign="top">' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . '</td>' . "\n" .
			'          </tr>' . "\n";
		}
		$items[4]='<tr><td colspan=3 class=contenttitle></td></tr><tr><td></td><td align=right class="main_item"><b>' . TEXT_TOTAL . '</b></td><td align=right class="main_item">' . $currencies->format($net_amount) . '</td></tr>';
		for($j=0;$j<=4;$j++)
		{
			if(isset($items[$j]))
			{?>
			<tr>
				<td class="main_item" colspan="3"><?php echo '<b>' . tep_get_title($j) . '</b>'; ?></td>
			</tr>
			<tr>
				<td>
					<table width="95%" align=right cellpadding="5">
			<?php 
				echo $items[$j];?>
			</table
				></td>
			</tr>
			<?php
			}
		}
	?>
</table>
 	<tr>
		<td class=infoBoxHeading><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	</tr>       
<?php
      if (isset($HTTP_GET_VARS['payment_error']) && is_object(${$HTTP_GET_VARS['payment_error']}) && ($error = ${$HTTP_GET_VARS['payment_error']}->get_error())) {?>
        <tr><td>
 	  <table border="0" width="100%" cellspacing="0" cellpadding="0">
	    <tr><td align=left class='pageHeading' colspan='2'><?php echo tep_output_string_protected($error['title']); ?></td></tr>
	  </table></td></tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" bgcolor="#ff6c6c">
          <tr class="infoBoxNoticeContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main" width="100%" valign="top"><font color=black><?php echo $error['error']; ?></font></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
      </tr>
<?php } ?>
		 <tr>
		 <?php  if (isset($HTTP_GET_VARS['error_message'])){ ?>
         <td colspan="2" class='main' align="left"><font color=red><?php echo tep_check_error($HTTP_GET_VARS['error_message']); ?></font></td>
		 <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
<?php } ?>
		 </tr>

      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
      </tr>
	<script language="JavaScript">
		function updateDetail(){
			document.edit_order.detail_only.value=1;
			document.edit_order.submit();
		}
		function setpayment(pid)
		{
			payment_length=document.edit_order.payment_select.length;
			for(i=0;i<payment_length;i++) {
				if(document.edit_order.payment_select[i].value==pid) {
					document.edit_order.payment_select[i].checked=true;
					break;
				}
			}
			document.edit_order.payment.value=pid;
		}
	</script>
 	<input type=hidden name='amount' value='<?php echo $net_amount; ?>'>
	<input type=hidden name="tax_amount" value="<?php echo $updated_tax; ?>">
 	<input type=hidden name='detail_only' value='0'>
<?php  echo tep_draw_hidden_field('payment');


if(!tep_session_is_registered('net_amount'))
		tep_session_register('net_amount');
	if(!tep_session_is_registered('updated_tax'))
		tep_session_register('updated_tax');	
if ($net_amount!=0){ ?>
      <tr>
	<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','5'); ?></td>
      </tr>
	<tr>
	   <td class="Pageheading">
	                 <?php if ($display_title=='customer')
					 	echo TEXT_CUSTOMER_PAYMENT_METHOD;
			       else
				   		echo TEXT_ADMIN_PAYMENT_METHOD;	
			 ?></td>
	</tr>
      <tr>
	<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1','3'); ?></td>
      </tr>
<!-- Begin Payment Block -->
      <tr>
        <td><table border="0" width="60%" cellspacing="1" cellpadding="2" >
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
 $order_timestamp=time();
 $order=new order($oID);
 $referenceID= substr(strtolower($order_detail->customer['firstname']),0,3) . substr(strtolower($order_detail->customer['lastname']),0,3) . $order_timestamp ;
  if (!tep_session_is_registered('referenceID')) tep_session_register('referenceID');
  
  $selection = $payment_modules->selection();
/*  if (sizeof($selection) > 1) {
?>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main" width="50%" valign="top"><b><?php echo TEXT_SELECT_PAYMENT_METHOD; ?></b></td>
                <td class="main" width="50%" valign="top" align="right"><b><?php echo TITLE_PLEASE_SELECT; ?></b><br><?php echo tep_image(DIR_WS_IMAGES . 'arrow_east_south.gif'); ?></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
<?php
  } elseif (sizeof($selection) != 0) {
?>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main" width="100%" colspan="2"><?php echo TEXT_ENTER_PAYMENT_INFORMATION; ?></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
<?php
  }*/
	$flag='B';
	 $radio_buttons = 0;
	 $item_count=0;
  //$cnt=1;
	$service_query=tep_db_query("select op.* from ". TABLE_ORDERS_EDIT_PRODUCTS . " op ," .TABLE_ORDERS . " o where o.orders_id=op.orders_id and op.orders_id='".$oID."'");
	while($service_result=tep_db_fetch_array($service_query)){
		if($service_result['products_type']=='S' || $service_result['products_type']=='P' || $service_result['products_type']=='E')
			$item_count+=1;
	}
  for ($i=0, $n=sizeof($selection); $i<$n; $i++) {
  	if($selection[$i]['id']=='internal'){
		if($item_count>=1){
			$i++;
		}
	 }
  	
?>  
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
	
	if ( ($selection[$i]['id'] == $payment) || ($n == 1) ) {
		content_title_top($selection[$i]['module'],$selection[$i]['id'],false,true,false,'setpayment(\'' .$selection[$i]['id'] . '\')');
				
		echo "<script>";
		echo 'setpayment(\'' .$selection[$i]['id'] . '\');';
		$title=$selection[$i]['module'];
		$title=str_replace(" ","_",$title);
		$title=str_replace("\"","",$title);
		echo "prev_focus_id='" .$title . "';";
		echo "</script>";
	}
	else {
		content_title_top($selection[$i]['module'],$selection[$i]['id'],false,true,true,'setpayment(\'' .$selection[$i]['id'] . '\')'); 
	}  ?>
 
 <?php
    $individual_payment=false;
    if (sizeof($selection) > 1) {
      //echo tep_draw_radio_field('payment', $selection[$i]['id']);
    } else {
	$individual_payment=true;
    }
    echo "<input type=hidden name=check_payment value='" . $selection[$i]['module'] . "'>";
?>
<?php
    if (isset($selection[$i]['error'])) {
?>
                  <tr>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td class="main" colspan="4"><?php echo $selection[$i]['error']; ?></td>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
<?php
    } elseif (isset($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
		 ?>
		 	<tr>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td colspan="4"><table border="0" cellspacing="0" cellpadding="2">
<?php
      for ($j=0, $n2=sizeof($selection[$i]['fields']); $j<$n2; $j++) {
?>
                      <tr>
                        <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                        <td class="main" nowrap><?php echo $selection[$i]['fields'][$j]['title']; ?></td>
                        <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                        <td class="main" nowrap><?php echo $selection[$i]['fields'][$j]['field']; ?></td>
                        <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                      </tr>
				<?php   } ?>
                    </table></td></tr>
<?php
    }
?><?php //tep_content_title_bottom();
echo '
					</table>
				</td>
			</tr>
  			</table>
			</td>
		  </tr>';
?>
                </table>
			
<?php
    $radio_buttons++;
    //$cnt++;
	
  }
?>
<?php
		if (sizeof($selection)==0 && $net_amount!=0)
		  echo '<tr><td class="main">' . TEXT_NO_PAYMENT_MODULE . '</td></tr>';
		else if ($net_amount==0)
		  echo '<tr><td class="main">' . TEXT_NO_UPDATION . '</td></tr>'; ?>
	<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	</tr>
            </table></td>
          </tr>
        </table></td>
<script language="javascript">
	previousPaymentSelected="<?php echo $payment;?>";
	var submitter = null;
	function hide_credit(){
		document.getElementById("credit").style.display="none";
		document.getElementById("update").style.display="";
		if(document.edit_order.coupon.checked==true){
			document.getElementById("credit").style.display="";
			document.getElementById("update").style.display="none";
		}
	}
function submitFunction(cnt) {
   submitter = 1;
   if(document.getElementById("credit")) var disp_coupon=document.getElementById("credit").innerHTML;
   if(!cnt) cnt=0;
   var cc_id="";
   var coupon="";
   var frm_credit=document.getElementById("credit");
   var frm_credit_result=document.getElementById("credit_result");
   if(document.getElementById("gv_redeem_code")) cc_id=document.getElementById("gv_redeem_code").value;
   if(document.edit_order.coupon && document.edit_order.coupon.checked) coupon=document.edit_order.coupon.value;
   if(!cnt){
     	frm_credit_result.innerHTML="<?php echo '<span class=smalltext> '.TEXT_PROCESSING_COUPON.'</span>';?>";
     	frm_credit_result.style.display='';
     	frm_credit.style.display='none';	
		document.getElementById("update").style.display="";
     	command="<?php echo tep_href_link(FILENAME_EDIT_ORDERS_CONFIRM,'do_action=get_counpon_details','NONSSL',true,false);?>&gv_redeem_code="+cc_id+"&coupon="+coupon;
		do_get_command(command);
   } 
   if(cnt==1)  {
   	frm_credit.style.display='';
   	if(document.edit_order.coupon)  document.edit_order.coupon.checked=false;
   	hide_credit();
   	if(document.getElementById("gv_chk")) document.getElementById("gv_chk").style.display='';
   	frm_credit_result.style.display='none';
   } 
}
function do_result(result){
  var frm_credit=document.getElementById("credit");
  var frm_credit_result=document.getElementById("credit_result");
  if(document.getElementById("loading_display")) document.getElementById("loading_display").style.display='none';
  if(frm_credit_result && result){
  	if(frm_credit_result) frm_credit_result.innerHTML=result;
  	frm_credit_result.style.display='';
 	if(result.indexOf('Uses Remain')>0 && result.indexOf('Valid Until')>0) {
 		if(document.getElementById("gv_chk")) document.getElementById("gv_chk").style.display='none';
 		frm_credit.style.display='none';
		if(document.getElementById("error_span"))
 			document.getElementById("error_span").style.display='none';
 	}
 	else  {
 		if(document.getElementById("error_span")){
 			document.getElementById("error_span").style.display='';
 			document.getElementById("error_span").innerHTML=result;
 		} 
 		frm_credit_result.style.display='none';
 		frm_credit.style.display='';	
 	}	
  } 	
}
</script>			
<!-- End Payment Block -->
<?php } ?>
<?php  $coupon_check_qry = tep_db_query("select * from " . TABLE_COUPONS . " where now() <= coupon_expire_date and now() >= coupon_start_date and coupon_active='Y' ");
		if(tep_db_num_rows($coupon_check_qry)){
?>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif','100%','5')?></td>
	</tr>	
	<?php tep_content_title_top('Gift Vouchers')?>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif','100%','5')?></td>
	</tr>	
	<tr>
	
		<td class="main">
		<table border="0" width="60%" cellspacing="1" cellpadding="2" >
			<tr><td id="error_span"></td></tr>
			<tr id="gv_chk">
				<td class="main" height="20"><?php //echo tep_draw_separator('pixel_trans.gif',40,1); ?>&nbsp;&nbsp;&nbsp;&nbsp;<b>Redeem your Gift Voucher: </b> <?php echo tep_draw_checkbox_field('coupon','1',false,'','onclick=javascript:hide_credit()');?></td>
			</tr>
	       <tr>
					   <td id="credit_result" class="smalltext" align="center" style="display:none;height:100;width:100%;">
					   </td>
			</tr>
			<tr id="credit" style="display:none">
				<td class="main">
				   <table border="0" cellpadding="0" cellspacing="0" width="100%">
				    <tr height="8"><td></td></tr>
					<tr>
					   <td class="main" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;Discount Coupon/Gift Voucher Redeem</td>
					 </tr>  
				    <tr>
					   <td>
					   	<table>
						<?php echo $coupon_class->credit_selection(); ?>
						</table>	
						</td>
					</tr>
					</table>
				</td>
			</tr>
			<?php tep_content_title_bottom()?>
      	</table>
	  </td>
      </tr>
	  	<tr>
		<td class="contentTitle"><?php echo tep_draw_separator('pixel_trans.gif', '1', '2'); ?></td>
	</tr>

<?php } 
 } ?>
<?php if ($step==2) {?>
	<script language="javascript">
		function rowOverEffect(object) {
  			if (object.className == 'moduleRow') object.className = 'moduleRowOver';
 		}

		function rowOutEffect(object) {
		  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
		}
		function do_actions(type,mode){
			var select_box;
			var ids="";
			switch(type){
				case "product":
					if (mode=="edit"){
						action_url="<?php echo tep_href_link(FILENAME_ADDPRODUCTS,"oID=$oID&action=add_product&mode=edit&id=");?>";
					} else {
						action_url="<?php echo tep_href_link(FILENAME_EDIT_ORDERS,"oID=$oID&action=delete_item&id=");?>";
					}
					select_box=document.edit_order.elements["select_products"];
					break;
				case "event":
					break;
				case "subscription":
					if (mode=="edit"){
						action_url="<?php echo tep_href_link(FILENAME_ADDSUBSCRIPTIONS,"oID=$oID&action=add_subscription&mode=edit&id=");?>";
					} else {
						action_url="<?php echo tep_href_link(FILENAME_EDIT_ORDERS,"oID=$oID&action=delete_item&id=");?>";
					}
					select_box=document.edit_order.elements["select_subscriptions"];
					break;
				case "service":
				 if (mode=="edit"){
						action_url="<?php echo tep_href_link(FILENAME_ADD_SERVICES,"oID=$oID&mode=edit&id=");?>";
					} else {
						action_url="<?php echo tep_href_link(FILENAME_EDIT_ORDERS,"oID=$oID&action=delete_item&id=");?>";
					}
					select_box=document.edit_order.elements["select_service"];
					break;
			}
			if (select_box[0]){
				for (icnt=0;icnt<select_box.length;icnt++){
					if (select_box[icnt].checked){
						ids=ids+select_box[icnt].value+",";
						if (mode=="edit") break;
					}
				}
				if (ids!="") ids=ids.substr(0,ids.length-1);
			} else {
				if (select_box.checked){
					ids=select_box.value;
				}
			}
			if (ids==""){
				alert((mode=="edit"?"<?php echo ERR_SELECT_EDIT;?>":"<?php echo ERR_SELECT_DELETE;?>"));
				return;
			}
			action_url=action_url+ids;
			location.href=action_url;
		}
		function do_actions_event(mode){
			var select_box=document.edit_order.elements["select_events"];
			var select_type=document.edit_order.elements["select_type"];
			var ids="";
			var id_types="";
			var edit_type="";
			if (mode=="edit"){
				action_url="<?php echo tep_href_link(FILENAME_ADD_EVENTS,"oID=$oID&mode=edit");?>";
			} else {
				action_url="<?php echo tep_href_link(FILENAME_EDIT_ORDERS,"oID=$oID&action=delete_event&id=");?>";
			}
			if (select_box[0]){
				for (icnt=0;icnt<select_box.length;icnt++){
					if (select_box[icnt].checked){
						if (mode=="delete"){
							id_types=id_types+(select_type[icnt].value=="group"?"g":"s")+",";
						}
						edit_type=select_type[icnt].value;
						ids=ids+select_box[icnt].value+",";
						if (mode=="edit") break;
					}
				}
				if (ids!="") ids=ids.substr(0,ids.length-1);
				if (id_types!="") id_types=id_types.substr(0,id_types.length-1);
			} else {
				if (select_box.checked){
					if (mode=="delete"){
						id_types=(select_type.value=="group"?"g":"s");
					}
					edit_type=select_type.value;
					ids=select_box.value;
				}
			}
			if (ids==""){
				alert((mode=="edit"?"<?php echo ERR_SELECT_EDIT;?>":"<?php echo ERR_SELECT_DELETE;?>"));
				return;
			}
			if (mode=="edit" && edit_type=="group"){
				action_url=action_url+"&eId="+ids;
			} else if (mode=="edit"){
				action_url=action_url+"&id="+ids;
			} else {
				action_url=action_url+ids+"&id_types="+id_types;
			}
			location.href=action_url;
		}
	</script>
	<tr>
		 <td class=infoBoxHeading><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td> 
	</tr>
	<!-- Begin Hide Products -->
    <?php if(HIDE_FROM_BACKEND_MENU_PRODUCTS=='false'){?>
	<?php tep_content_title_top(TEXT_HEADING_PRODUCTS); ?>
    
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
  <!-- Begin Products Listing Block -->
      <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="5" >
	<!-- Begin Products Listings Block -->
	<?
      	// Override order.php Class's Field Limitations
		
		$edit_attendees=false;
		$max_attendees=0;
	    $RunningSubTotal=0.0;
		$Tax=0.0;
		$RunningTax=0.0;
		$Total=0.0;
		$index = 0;
		$products_check=0;
		$order_detail->products = array();
		$orders_products_sql = "select * from " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_id = '" . (int)$oID . "' and products_type='P'";
		$orders_products_query = tep_db_query($orders_products_sql);
		while ($orders_products = tep_db_fetch_array($orders_products_query)) {
		$order_detail->products[$index] = array('qty' => $orders_products['products_quantity'],
										'name' => str_replace("'", "&#39;", $orders_products['products_name']),
                                        'model' => $orders_products['products_model'],
                                        'tax' => $orders_products['products_tax'],
                                        'price' => $orders_products['products_price'],
                                        'final_price' => $orders_products['final_price'],
										'products_type' => $orders_products['products_type'],
                                        'orders_products_id' => $orders_products['orders_products_id']);
		$subindex = 0;
		
		$attributes_query_string = "select * from " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$oID . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "' order by products_options_id";
	//	echo $attributes_query_string;
		$attributes_query = tep_db_query($attributes_query_string);

		if (tep_db_num_rows($attributes_query)) {
		while ($attributes = tep_db_fetch_array($attributes_query)) {
		
		  $order_detail->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
		  														   'optionid' => $attributes['products_options_id'],
		                                                           'value' => $attributes['products_options_values'],
																   'valueid' => $attributes['products_options_values_id'],
		                                                           'prefix'=> $attributes['price_prefix'],
		                                                           'price' => $attributes['options_values_price'],
		                                                           'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
												   
		$subindex++;
		}
		}
		$Tax=(($order_detail->products[$index]['tax'] / 100) * ($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']));
		$RunningSubTotal += ((($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']))+$Tax);
		$RunningTax+=$Tax;
		$index++;
		}
		$Total=$RunningSubTotal;
		$product_type="";
		$product_count=0;
	if(sizeof($order_detail->products)>0)
	{?>
		 <tr  height=30>
	    <td class="main" width=40><?php echo TABLE_HEADING_ACTION; ?></td>
	    <td class="main" colspan="2" align=center><?php echo TABLE_HEADING_PRODUCTS; ?></td>
	    <td class="main"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
	    <td class="main" align="center"><?php echo TABLE_HEADING_TAX; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_UNIT_PRICE; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_TOTAL_PRICE; ?></td>
	  </tr>
	<?php }
	for ($i=0; $i<sizeof($order_detail->products); $i++) {
		$product_type="P";
		$orders_products_id = $order_detail->products[$i]['orders_products_id'];
		$producttype=$order_detail->products[$i]['products_type'];
		$readonly="";
		if($producttype=='E'){
			$readonly="readonly";
		}else{
			$readonly="";
		}
		$RowStyle = "dataTableContent";
		echo '	  <tr class="' .  (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver') . '">' . "\n" .
		   '        <td class="' . $RowStyle . '" valign="top" align="right">' . tep_draw_checkbox_field("select_products",$orders_products_id,'') . '</td>' .
		   '	    <td class="' . $RowStyle . '" valign="top" align="right">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=P','update_qty'); class='inputNormal' name='update_products[$orders_products_id][qty]'  size='2' value='" . $order_detail->products[$i]['qty'] . "' " . $readonly . ">&nbsp;x</td>\n" . 
		   '	    <td class="' . $RowStyle . '" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=P','update_name'); class='inputNormal' name='update_products[$orders_products_id][name]' size='40' value='" . $order_detail->products[$i]['name'] . "'>";
		
		// Has Attributes?
		if (sizeof($order_detail->products[$i]['attributes']) > 0) {
			for ($j=0; $j<sizeof($order_detail->products[$i]['attributes']); $j++) {
				$orders_products_attributes_id = $order_detail->products[$i]['attributes'][$j]['orders_products_attributes_id'];
				echo '<br><nobr><small>&nbsp;<i> - ' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,$orders_products_attributes_id,'&value='+this.value+'&type=P','update_attribute_name'); class='inputNormal' name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][option]' size='6' value='" . $order_detail->products[$i]['attributes'][$j]['option'] . "'>";
				echo ': ' . "<input class='inputNormal' onblur=javascript:update_values(" . $oID . ",$orders_products_id,$orders_products_attributes_id,'&value='+this.value+'&type=P','update_attribute_value'); name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][value]' size='10' value='" . $order_detail->products[$i]['attributes'][$j]['value'] . "'>";
				echo '</i></small></nobr>';
			}
		}
		$Tax=(($order_detail->products[$i]['tax'] / 100) * ($order_detail->products[$i]['qty'] * $order_detail->products[$i]['final_price']));
		echo '	    </td>' . "\n" .
		     '      <td class="' . $RowStyle . '" valign="top">' . "<input class='inputNormal' name='update_products[$orders_products_id][model]' size='12' readonly=true value='" . $order_detail->products[$i]['model'] . "'>" . '</td>' . "\n" .
		     '	    <td class="' . $RowStyle . '" align="center" valign="top">' . "<input class='inputNormal' name='update_products[$orders_products_id][tax]' onblur=update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=P','update_tax'); size='3' value='" . tep_display_tax_value($order_detail->products[$i]['tax']) . "'>" . '%</td>' . "\n" .
		     '	    <td class="' . $RowStyle . '" align="right" valign="top">' . "<input class='inputNormal' name='update_products[$orders_products_id][final_price]' size='5' onblur=update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=P','update_uprice'); value='" . number_format($order_detail->products[$i]['price'], 2, '.', '') . "'>" . '</td>' . "\n" . 
			 '	    <td class="' . $RowStyle . '" align="right" valign="top" id="total_' . $orders_products_id . '">' . $currencies->format($Tax + $order_detail->products[$i]['final_price'] * $order_detail->products[$i]['qty'], true, $order_detail->info['currency'], $order_detail->info['currency_value']) . '</td>' . "\n" . 
		     '	  </tr>' . "\n";
		$products_check++;
		$product_count++;
	}
	?>
	<!-- End Products Listings Block -->
	<tr>
	    <td colspan=7 valign="middle"><br>
			<table width="100%" align="left" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td width="60"></td>
				    <td colspan=7 valign="middle">
			<?php 
				echo '<a href="' . tep_href_link(FILENAME_ADDPRODUCTS,"oID=$oID&action=add_product&step=1&mode=add") . '">' . tep_image_button('button_add.gif',IMAGE_ADD_PRODUCT,'align=absmiddle') . '</a>&nbsp;';
				if ($product_count>0){
					//echo '<a href="javascript:do_actions(\'product\',\'edit\')">' . tep_image_button('button_edit.gif',IMAGE_EDIT,'align=absmiddle'). '</a>&nbsp;<a href="javascript:do_actions(\'product\',\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE,'align=absmiddle') . '</a>';
					echo '<a href="javascript:do_actions(\'product\',\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE,'align=absmiddle') . '</a>';

				}
			?>     </td>
			   </tr>
			 </table>
		</td>
	</tr>
	</table><td></tr>
		<?php tep_content_title_bottom(); ?>
    <?php } ?>
    <!-- end  for checking hide product -->		
	<!-- Begin Hide Events -->
    <?php if(HIDE_FROM_BACKEND_MENU_EVENTS=='false'){?>
		<?php tep_content_title_top(TEXT_HEADING_EVENTS); ?>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
<!-- Begin Events Listing Block -->
      <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="5">
	<!-- Begin Products Listings Block -->
	<?
      	// show the event details from the order
		$index = 0;
		$order_detail->products = array();
		$orders_products_query = tep_db_query("select s.start_date,s.events_id,op.orders_products_id,op.products_quantity,op.products_name,op.products_model,op.products_tax,op.products_price,op.final_price,op.products_type,op.events_type,op.waitlist_type from " . TABLE_ORDERS_EDIT_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS . " s where op.orders_id = '" . (int)$oID . "' and op.products_type='E' and op.products_id=s.sessions_id order by op.products_name,s.start_date");
		$events_style_waitlist=array();
		$prev_event=0;
		while ($orders_products = tep_db_fetch_array($orders_products_query)) {
		// fetch every event waiting list style into an array
		if ($prev_event!=$orders_products["events_id"]){
			$prev_event=$orders_products["events_id"];
			$events_style_waitlist[$prev_event]=0;
			$event_query=tep_db_query("SELECT session_style from " . TABLE_EVENTS . " where events_id='" . (int)$prev_event ."'");
			$events_style_result=tep_db_fetch_array($event_query);
			if ($events_style_result["session_style"]=='E') $events_style_waitlist[$prev_event]=1;
		}
		if ($orders_products['products_quantity']>1){
			$edit_attendees=true;
			$max_attendees=$orders_products['products_quantity'];
		}
		
		// fetch the event details
		$order_detail->products[$index] = array('qty' => $orders_products['products_quantity'],
                                        'name' => str_replace("'", "&#39;", $orders_products['products_name']),
                                        'model' => $orders_products['start_date'],
                                        'tax' => $orders_products['products_tax'],
                                        'price' => $orders_products['products_price'],
                                        'final_price' => $orders_products['final_price'],
										'products_type' => $orders_products['products_type'],
										'events_type'=>$orders_products['events_type'],
										'events_id'=>$orders_products['events_id'],
                                        'orders_products_id' => $orders_products['orders_products_id']);
		$subindex = 0;

		$attributes_query_string = "select * from " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$oID . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "' order by products_options_id";
		$attributes_query = tep_db_query($attributes_query_string);

		if (tep_db_num_rows($attributes_query)) {
		while ($attributes = tep_db_fetch_array($attributes_query)) {
		  $order_detail->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
		                                                           'value' => $attributes['products_options_values'],
		                                                           'prefix' => $attributes['price_prefix'],
		                                                           'price' => $attributes['options_values_price'],
		                                                           'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
		$subindex++;
		}
		}
		$Tax=(($order_detail->products[$index]['tax'] / 100) * ($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']));
		$RunningSubTotal += ((($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']))+$Tax);
		$RunningTax+=$Tax;
		$index++;
		}
		$Total=$RunningSubTotal;
		$prev_event=0;
		$event_count=0;
		if(sizeof($order_detail->products)>0) {?>
		 <tr  height=30>
	    <td class="main" width=40><?php echo TABLE_HEADING_ACTION; ?></td>
	    <td class="main" colspan="2" align="center"><?php echo TABLE_HEADING_EVENTS; ?></td>
	    <td class="main"><?php echo TABLE_HEADING_EVENTS_SESSION; ?></td>
	    <td class="main" align="center"><?php echo TABLE_HEADING_TAX; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_UNIT_PRICE; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_TOTAL_PRICE; ?></td>
	  </tr>
		<?php }	//print_r($order_detail->products);
	for ($i=0; $i<sizeof($order_detail->products); $i++) {
	    if ($product_type=="P") $product_type="M";
		else if ($product_type!="M") $product_type="E";
		
		$orders_products_id = $order_detail->products[$i]['orders_products_id'];
		$producttype=$order_detail->products[$i]['products_type'];
		$readonly="";
		if($producttype=='E'){
			$readonly="readonly";
		} else{
			$readonly="";
		}
		if ($order_detail->products[$i]['events_type']=='R') $color="#000000";
		else $color="#FFA715";
		$RowStyle = "dataTableContent";
		//check for events style waitlist
		//print_r($order_detail->products);
		if ($order_detail->products[$i]["events_type"]=='W' && $events_style_waitlist[$order_detail->products[$i]["events_id"]]==1){
			//  check the session item amount for none
			if ($order_detail->products[$i]['final_price']!=0){
				$prev_event=$order_detail->products[$i]["events_id"];
				echo '	  <tr height=30 class="' .  (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver') . '">' . "\n" .
					 '        <td class="' . $RowStyle . '" valign="middle" align="right">'. tep_draw_checkbox_field("select_events",$prev_event) . tep_draw_hidden_field("select_type","group") . '</a></td>' .
					 '	    <td></td><td class="' . $RowStyle . '" valign="middle">' . $order_detail->products[$i]['name'] . "</td>\n" . 
					 '	    <td class="main" valign="middle"><font color="' . $color . '">' . TEXT_WAITLIST . "</font></td>\n" . 
					 '	    <td class="' . $RowStyle . '" valign="middle">' . tep_display_tax_value($order_detail->products[$i]['tax']) . "%</td>\n" . 
 					 '	    <td class="' . $RowStyle . '" valign="middle" align="right">' . number_format($order_detail->products[$i]['final_price'], 2, '.', '') . "</td>\n" . 
					 '	    <td class="' . $RowStyle . '" valign="middle" align="right">' . $currencies->format($order_detail->products[$i]['final_price'] * $order_detail->products[$i]['qty'], true, $order_detail->info['currency'], $order_detail->info['currency_value']) . "</td>\n";
			}
			echo	"<input type='hidden' name='update_products[$orders_products_id][qty]'   value='" . $order_detail->products[$i]['qty'] . "' " . $readonly . ">" . 
					"<input type='hidden' name='update_products[$orders_products_id][name]'  value='" . $order_detail->products[$i]['name'] . "'>" . 
		 			"<input type='hidden' name='update_products[$orders_products_id][model]' value='" . $order_detail->products[$i]['model'] . "'>" . 
					"<input type='hidden' name='update_products[$orders_products_id][tax]' value='" . tep_display_tax_value($order_detail->products[$i]['tax']) . "'>" . 
					"<input type='hidden' name='update_products[$orders_products_id][final_price]' value='" . number_format($order_detail->products[$i]['final_price'], 2, '.', '') . "'>";
		} else {
			echo '	  <tr height=30 class="' .  (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver') . '">' . "\n" .
			   '        <td class="' . $RowStyle . '" valign="top" align="right">' . tep_draw_checkbox_field("select_events",$orders_products_id) . tep_draw_hidden_field("select_type","single") . '</td>' .
			   '	    <td class="' . $RowStyle . '" valign="top" align="right">' . "<input class='inputNormal' name='update_products[$orders_products_id][qty]'  size='2' value='" . $order_detail->products[$i]['qty'] . "' " . $readonly . ">&nbsp;x</td>\n" . 
			   '	    <td class="' . $RowStyle . '" valign="top" align="left">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=E','update_name'); class='inputNormal' name='update_products[$orders_products_id][name]' size='40' value='" . $order_detail->products[$i]['name'] . "'>";
	
			// Has Attributes?
			if (sizeof($order_detail->products[$i]['attributes']) > 0) {
				for ($j=0; $j<sizeof($order_detail->products[$i]['attributes']); $j++) {
					$orders_products_attributes_id = $order_detail->products[$i]['attributes'][$j]['orders_products_attributes_id'];
					echo '<br><nobr><small>&nbsp;<i> - ' . "<input class='inputNormal' name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][option]' size='6' value='" . $order_detail->products[$i]['attributes'][$j]['option'] . "'>" . ': ' . "<input class='inputNormal' name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][value]' size='10' value='" . $order_detail->products[$i]['attributes'][$j]['value'] . "'>";
					echo '</i></small></nobr>';
				}
			}

			$Tax=(($order_detail->products[$i]['tax'] / 100) * ($order_detail->products[$i]['qty'] * $order_detail->products[$i]['final_price']));
			echo '	    </td>' . "\n" .
				 '	    <td class="' . $RowStyle . '" valign="top">' . "<input class='inputNormal' name='update_products[$orders_products_id][model]' size='12' readonly=true value='" . format_date($order_detail->products[$i]['model'])  . "' style='color:" . $color . "'>" . '</td>' . "\n" .
				 '	    <td class="' . $RowStyle . '" align="center" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=E','update_tax'); class='inputNormal' name='update_products[$orders_products_id][tax]' size='3' value='" . tep_display_tax_value($order_detail->products[$i]['tax']) . "'>" . '%</td>' . "\n" .
				 '	    <td class="' . $RowStyle . '" align="right" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=E','update_uprice'); class='inputNormal' name='update_products[$orders_products_id][final_price]' size='5' value='" . number_format($order_detail->products[$i]['price'], 2, '.', '') . "'>" . '</td>' . "\n" . 
				 '	    <td class="' . $RowStyle . '" align="right" valign="top" id="total_' . $orders_products_id . '">' . $currencies->format($Tax + ($order_detail->products[$i]['final_price'] * $order_detail->products[$i]['qty']), true, $order_detail->info['currency'], $order_detail->info['currency_value']) . '</td>' . "\n" . 
				 '	  </tr>' . "\n";
		}
		$products_check++;
		$event_count++;
	}
	?>
	<!-- End Events Listings Block -->
	<tr class="<?php echo (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver');?>">
	   <td colspan=7 valign="middle"><br>
		<table width="100%" align="left" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td width="60"></td>
				    <td colspan=7 valign="middle">
		<?php 
				//error_reporting(E_ALL);
				if($edit_attendees){ 
				   echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_ATTENDEES, 'oID=' . $oID . '&mode=edit'  . '&no_attendees=' . ($max_attendees-1)).'"><b>' . TEXT_MULTIPLE_ATTENDEES  . '</b></a><br>' .
					$edit_cart->get_attendee_names(",") . '<br>';
				}
			echo '<a href="' . tep_href_link(FILENAME_ADD_EVENTS,"oID=$oID&step=1&mode=add") . '">' . tep_image_button('button_add.gif',IMAGE_ADD_EVENT,'align=absmiddle') . '</a>&nbsp;';
			if ($event_count>0){
				//echo '<a href="javascript:do_actions_event(\'edit\')">' . tep_image_button('button_edit.gif',IMAGE_EDIT,'align=absmiddle'). '</a>&nbsp;<a href="javascript:do_actions_event(\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE,'align=absmiddle') . '</a>';
				echo '</a>&nbsp;<a href="javascript:do_actions_event(\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE,'align=absmiddle') . '</a>';
			}
		?>      </td>
		     </tr>
	   </table>
	  </td>
	</tr></table><td></tr>
		<?php tep_content_title_bottom(); ?>

	<?php }?>
    <!-- End for Hide Events-->
	<!-- Begin Hide Subscriptions -->
   <?php if(HIDE_FROM_BACKEND_MENU_SUBSCRIPTIONS=='false'){?>
		<?php tep_content_title_top(TEXT_HEADING_SUBSCRIPTIONS); ?>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
	<!-- Begin subscription Listing Block -->
      <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="5" >
	<!-- Begin Subscription Listings Block -->
	<?
      	// Override order.php Class's Field Limitations
		$index = 0;
		$order_detail->products = array();
		$orders_products_query = tep_db_query("select * from " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_id = '" . (int)$oID . "' and products_type='S'");
		while ($orders_products = tep_db_fetch_array($orders_products_query)) {
		$order_detail->products[$index] = array('qty' => $orders_products['products_quantity'],
                                        'name' => str_replace("'", "&#39;", $orders_products['products_name']),
                                        'tax' => $orders_products['products_tax'],
                                        'price' => $orders_products['products_price'],
                                        'final_price' => $orders_products['final_price'],
										'products_type' => $orders_products['products_type'],
                                        'orders_products_id' => $orders_products['orders_products_id'],
										'model'=>$orders_products['products_model']);
		$subindex = 0;

		$attributes_query_string = "select * from " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$oID . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'";
		$attributes_query = tep_db_query($attributes_query_string);

		/*if (tep_db_num_rows($attributes_query)) {
			while ($attributes = tep_db_fetch_array($attributes_query)) {
			 $order_detail->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
																	  'value' => $attributes['products_options_values'],
																		'prefix' => $attributes['price_prefix'],
																	   'price' => $attributes['options_values_price'],
																	  'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
			$subindex++;
			}
		}*/
		$Tax=(($order_detail->products[$index]['tax'] / 100) * ($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']));

		$RunningSubTotal += ((($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']))+$Tax);
		$RunningTax+=$Tax;
		$index++;
		}
		$Total=$RunningSubTotal;
		$product_type="";
		$subscription_count=0;
		if(sizeof($order_detail->products)>0){?>
		 <tr  height=30>
	    <td class="main" width=40><?php echo TABLE_HEADING_ACTION; ?></td>
	    <td class="main" colspan="2" align=center><?php echo TABLE_HEADING_SUBSCRIPTIONS; ?></td>
		<td class="main" align="left"><?php echo TABLE_HEADING_PRODUCTS_TYPE; ?></td>
	    <td class="main" align="center"><?php echo TABLE_HEADING_TAX; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_UNIT_PRICE; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_TOTAL_PRICE; ?></td>
	  </tr>
		<?php }
	for ($i=0; $i<sizeof($order_detail->products); $i++) {
		$product_type="S";
		$orders_products_id = $order_detail->products[$i]['orders_products_id'];
		$producttype=$order_detail->products[$i]['products_type'];
		$readonly="";
		if($producttype=='S'){
			$readonly="readonly";
		}
		else{
			$readonly="";
		}
		$RowStyle = "dataTableContent";
		
		echo '	  <tr class="' .  (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver') . '">' . "\n" .
		   '        <td class="' . $RowStyle . '" valign="top" align="right">' . tep_draw_checkbox_field("select_subscriptions",$orders_products_id,'') . '</td>' .
		   '	    <td class="' . $RowStyle . '" valign="top" align="right">' . "<input class='inputNormal' name='update_products[$orders_products_id][qty]'  size='2' value='" . $order_detail->products[$i]['qty'] . "' " . $readonly . ">&nbsp;x</td>\n" . 
		   '	    <td class="' . $RowStyle . '" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=S','update_name'); class='inputNormal' name='update_products[$orders_products_id][name]' size='40' value='" . $order_detail->products[$i]['name'] . "'>";
		
		// Has Attributes?
	/*	if (sizeof($order_detail->products[$i]['attributes']) > 0) {
			for ($j=0; $j<sizeof($order_detail->products[$i]['attributes']); $j++) {
				$orders_products_attributes_id = $order_detail->products[$i]['attributes'][$j]['orders_products_attributes_id'];
				echo '<br><nobr><small>&nbsp;<i> - ' . "<input name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][option]' size='6' value='" . $order_detail->products[$i]['attributes'][$j]['option'] . "'>" . ': ' . "<input name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][value]' size='10' value='" . $order_detail->products[$i]['attributes'][$j]['value'] . "'>";
				echo '</i></small></nobr>';
			} 
		}*/
				
		$Tax=(($order_detail->products[$i]['tax'] / 100) * ($order_detail->products[$i]['qty'] * $order_detail->products[$i]['final_price']));
		echo '	    </td>' . "\n" .
 			 '	    <td class="' . $RowStyle . '" valign="top" align="left">'.tep_draw_input_field("update_products[$orders_products_id][model]",$order_detail->products[$i]['model']," size=12 readonly=true ") . '</td>' . "\n" .
		     '	    <td class="' . $RowStyle . '" align="center" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=S','update_tax'); class='inputNormal' name='update_products[$orders_products_id][tax]' size='3' value='" . tep_display_tax_value($order_detail->products[$i]['tax']) . "'>" . '%</td>' . "\n" .
			 '	    <td class="' . $RowStyle . '" align="right" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=S','update_uprice'); class='inputNormal' name='update_products[$orders_products_id][final_price]' size='5' value='" . number_format($order_detail->products[$i]['price'], 2, '.', '') . "'>" . '</td>' . "\n" . 
			 '	    <td class="' . $RowStyle . '" align="right" valign="top" id="total_' . $orders_products_id . '">' . $currencies->format($Tax + ($order_detail->products[$i]['final_price'] * $order_detail->products[$i]['qty']), true, $order_detail->info['currency'], $order_detail->info['currency_value']) . '</td>' . "\n" . 
		     '	  </tr>' . "\n";
		$products_check++;
		$subscription_count++;
	}
	?>
	<!-- End subscription Listings Block -->
	<tr class="<?php echo (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver');?>">
	    <td colspan=7><br>
			<table width="100%" align="left" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td width="60"></td>
				    <td colspan=7 valign="middle">
			<?php 
				echo '<a href="' . tep_href_link(FILENAME_ADDSUBSCRIPTIONS,"oID=$oID&action=add_subscription&step=1&mode=add") . '">' . tep_image_button('button_add.gif',IMAGE_ADD_SUBSCRIPTIONS,'align=absmiddle') . '</a>&nbsp;';
				if ($subscription_count>0){
					//echo '<a href="javascript:do_actions(\'subscription\',\'edit\')">' . tep_image_button('button_edit.gif',IMAGE_EDIT,'align=absmiddle'). '</a>&nbsp;<a href="javascript:do_actions(\'subscription\',\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE,'align=absmiddle') . '</a>';
					echo '</a>&nbsp;<a href="javascript:do_actions(\'subscription\',\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE,'align=absmiddle') . '</a>';
				}
			?>	   </td>
			  </tr>
			</table>
		  </td>	  
	</tr>
	</table><td></tr>
	<!-- End for Hide Products -->
		<?php tep_content_title_bottom(); ?>

  <?php }?>
	
   <!-- end of Subscription  Block-->
   <!-- start service entry -->
   	<?php tep_content_title_top(TEXT_HEADING_SERVICES); ?>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
<!-- Begin Products Listing Block -->
      <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="5" >
	<!-- Begin Products Listings Block -->
	<?php 
		// get the service timings
		$timings=array();
		$timing_query=tep_db_query("SELECT orders_products_id,resource_id,products_id,start_date,end_date,start_time,end_time from " . TABLE_ORDERS_EDIT_SERVICES . " where orders_id='" . $oID . "' order by orders_products_id");
		while($timing_result=tep_db_fetch_array($timing_query)){
			$timings[]=$timing_result;
		}
		$resource_value=array();
		$resource_query=tep_db_query("select orders_products_id,start_date,resource_id,products_id,end_date,start_time,end_time,resource_name  from ".TABLE_ORDERS_EDIT_SERVICES." where orders_id='".(int)$oID."' order by orders_products_id,resource_name");
		while($resource=tep_db_fetch_array($resource_query)){
			$resource_value[]=array('products_id'=>$resource['products_id'],'orders_products_id'=>$resource['orders_products_id'],'start_date'=>$resource['start_date'],'end_date'=>$resource['end_date'],'start_time'=>$resource['start_time'],'end_time'=>$resource['end_time'],'resource_id'=>$resource['resource_id'],'resource_name'=>$resource['resource_name']);		
		}
		
		//$res=get_details('resource_id,products_id,start_date,end_date,start_time,end_time','orders_edit_services'," orders_id='".$oID."'");
		// Override order.php Class's Field Limitations
		$index = 0;
		$products_check=0;
		$order_detail->products = array();
		$orders_products_query=tep_db_query("select * from " . TABLE_ORDERS_EDIT_PRODUCTS . " where orders_id = '" . (int)$oID . "' and products_type='V' order by orders_products_id");
	     	
		while ($orders_products = tep_db_fetch_array($orders_products_query)) {
		$order_detail->products[$index] = array(
						'qty' => $orders_products['products_quantity'],
                        'name' => str_replace("'", "&#39;", $orders_products['products_name']),
	                    'model' => $orders_products['products_model'],
	                    'tax' => $orders_products['products_tax'],
	                    'price' => $orders_products['products_price'],
	                    'final_price' => $orders_products['final_price'],
	 					'products_type' => $orders_products['products_type'],
	                    'orders_products_id' => $orders_products['orders_products_id'],
	 					'products_id' => $orders_products['products_id'],
						);
																		
		$subindex = 0;
					
		$attributes_query_string = "select * from " . TABLE_ORDERS_EDIT_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$oID . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'";
		$attributes_query = tep_db_query($attributes_query_string);

		if (tep_db_num_rows($attributes_query)) {
			while ($attributes = tep_db_fetch_array($attributes_query)) {
				  $order_detail->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
			                                                           'value' => $attributes['products_options_values'],
			                                                           'prefix' => $attributes['price_prefix'],
			                                                           'price' => $attributes['options_values_price'],
			                                                           'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
			 $subindex++;
		 	 }
		}
		$Tax=(($order_detail->products[$index]['tax'] / 100) * ($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']));
		$RunningSubTotal += ((($order_detail->products[$index]['qty'] * $order_detail->products[$index]['final_price']))+$Tax);
		$RunningTax+=$Tax;
		$index++;
		}
		$Total=$RunningSubTotal;
		$product_type="";
		$service_count=0;
		if(sizeof($order_detail->products)>0){?>
		 <tr  height=30>
	    <td class="main" width=40><?php echo TABLE_HEADING_ACTION; ?></td>
	    <td class="main" colspan="2" align=center><?php echo TABLE_HEADING_SERVICES; ?></td>
	    <td class="main"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
	    <td class="main" align="center"><?php echo TABLE_HEADING_TAX; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_UNIT_PRICE; ?></td>
	    <td class="main" align="right"><?php echo TABLE_HEADING_TOTAL_PRICE; ?></td>
	  </tr>
		<?php } 
	for ($i=0; $i<sizeof($order_detail->products); $i++) {
		$product_type.="V";
		$products_id = $order_detail->products[$i]['products_id'];
		$producttype=$order_detail->products[$i]['products_type'];
		$orders_products_id = $order_detail->products[$i]['orders_products_id'];
		
		//$resource_id = $order_detail->products[$i]['resources'][$i]['resource_id'];
		$RowStyle = "dataTableContent";
		echo '  <tr class="' .  (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver') . '">' . "\n" .
		   '        <td class="' . $RowStyle . '" valign="top" align="right">' . tep_draw_checkbox_field('select_service', $orders_products_id,'') .'</td>' .
		   '	   <td class="' . $RowStyle . '" valign="top" align="right">' . "<input class='inputNormal' name='update_products[$orders_products_id][qty]'  size='2' value='" . $order_detail->products[$i]['qty'] . "' readonly >&nbsp;x</td>\n" .
		   '	   <td class="' . $RowStyle . '" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=V','update_name'); class='inputNormal' name='update_products[$orders_products_id][name]' size='40' value='" . $order_detail->products[$i]['name'] . "'>";
		
		// Has Attributes?
		//echo $orders_products_id; 
							
		if($timings[$i]["start_time"]=='') $timings[$i]["start_time"]=date('h:i:s');
		if($timings[$i]["end_time"]=='') $timings[$i]["end_time"]=date('h:i:s');
		
		if($timings[$i]["end_date"] && $timings[$i]["end_time"]){ 	
				$str_time=strtotime($timings[$i]['end_date'].' '.$timings[$i]["end_time"])+60;
				$end_date_display=date('Y-m-d',$str_time); 
				$end_time_display=date('h:i A',$str_time);
		}
		//echo '<br><small>' . sprintf(TEXT_START_DATE . " - %s %s",format_date($timings[$i]["start_date"]),date("h:i A",strtotime((($timings[$i]["start_time"]=='24:00:00')?'12:00:00':$timings[$i]["start_time"])))) . '&nbsp;&nbsp;&nbsp;<br>' . sprintf(TEXT_END_DATE . " - %s %s",format_date($end_date_display),$end_time_display) . '</small><br>';
		for($j=0;$j<=sizeof($resource_value);$j++){ 
			
			$start_date=$resource_value[$j]['start_date'];
			$start_time=$resource_value[$j]['start_time'];
			$end_time=$resource_value[$j]['end_time'];
			$end_date=$resource_value[$j]['end_date'];
			if($start_time=='') $start_time=date('h:i:s');
			if($end_time=='') $end_time=date('h:i:s');
			if($end_date && $end_time){ 	
				$str_time=strtotime($end_date.' '.$end_time)+60;
				$end_date_display=date('Y-m-d',$str_time); 
				$end_time_display=date('h:i A',$str_time);
			}			
			/*if($resource_value[$j]['start_time']==$timings[$i]["start_time"] && $resource_value[$j]['end_time']==$timings[$i]["end_time"] &&  $resource_value[$j]['orders_products_id']==$orders_products_id && $resource_value[$j]['resource_id']==$timings[$i]["resource_id"] && $resource_value[$j]['products_id']==$products_id){
			  if($resource_value[$j]['resource_name']!="") echo '<small>'.TEXT_RESOURCE_NAME . '  ' .$resource_value[$j]['resource_name'] . '</small> '; 
			}*/
			if($resource_value[$j]['orders_products_id']==$orders_products_id && $resource_value[$j]['products_id']==$products_id) echo '<br><small>' . sprintf(TEXT_START_DATE . " - %s %s",format_date($start_date),date("h:i A",strtotime((($start_time=='24:00:00')?'12:00:00':$start_time)))) . '&nbsp;&nbsp;&nbsp;<br>' . sprintf(TEXT_END_DATE . " - %s %s",format_date($end_date_display),$end_time_display) . '</small><br>';			
			if($resource_value[$j]['orders_products_id']==$orders_products_id && $resource_value[$j]['resource_name'] && $resource_value[$j]['products_id']==$products_id){
			  if($resource_value[$j]['resource_name']!="") echo '<small>'.TEXT_RESOURCE_NAME . '  ' .$resource_value[$j]['resource_name'] . '</small> '; 
			}
		}
		if (sizeof($order_detail->products[$i]['attributes']) > 0) {
			for ($j=0; $j<sizeof($order_detail->products[$i]['attributes']); $j++) {
				$orders_products_attributes_id = $order_detail->products[$i]['attributes'][$j]['orders_products_attributes_id'];
				echo '<br><nobr><small>&nbsp;<i> - ' . "<input style='border:0px' class='inputNormal' readonly name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][option]' size='14' value='" . $order_detail->products[$i]['attributes'][$j]['option'] . "'>" . ': ' . "<input style='border:0px' readonly name='update_products[$orders_products_id][attributes][$orders_products_attributes_id][value]' size='10' value='" . $order_detail->products[$i]['attributes'][$j]['value'] . "'>";
				echo '</i></small></nobr>';
				}
		}
		$Tax=(($order_detail->products[$i]['tax'] / 100) * ($order_detail->products[$i]['qty'] * $order_detail->products[$i]['final_price']));
		echo '  </td>' . "\n" .
		     '      <td class="' . $RowStyle . '" valign="top">' . "<input class='inputNormal' name='update_products[$orders_products_id][model]' size='12' readonly=true value='" . $order_detail->products[$i]['model'] . "'>" . '</td>' . "\n" .
		     '	   <td class="' . $RowStyle . '" align="center" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=V','update_tax'); class='inputNormal' name='update_products[$orders_products_id][tax]' size='3' value='" . tep_display_tax_value($order_detail->products[$i]['tax']) . "'>" . '%</td>' . "\n" .
		     '	   <td class="' . $RowStyle . '" align="right" valign="top">' . "<input onblur=javascript:update_values(" . $oID . ",$orders_products_id,0,'&value='+this.value+'&type=V','update_uprice'); class='inputNormal' name='update_products[$orders_products_id][final_price]' size='5' value='" . number_format($order_detail->products[$i]['price'], 2, '.', '') . "'>" . '</td>' . "\n" . 
		     '	   <td class="' . $RowStyle . '" align="right" valign="top" id="total_' . $orders_products_id . '">' . $currencies->format($Tax + ($order_detail->products[$i]['final_price'] * $order_detail->products[$i]['qty']), true, $order_detail->info['currency'], $order_detail->info['currency_value']) . '</td>' . "\n" . 
		     '	  </tr>' . "\n";
		$products_check++;
		$service_count++;
		echo tep_draw_hidden_field('time_id'.$order_detail->products[$i]['orders_products_id'],$timings[$i]["start_date"] .'#'.$timings[$i]["end_date"] .'#'.$timings[$i]["start_time"].'#'.$timings[$i]["end_time"]);	
		//}
	}?>
	
	<!-- End Products Listings Block -->
	<!--<tr class="<?php //echo (floor($i/2) == ($i/2) ? 'dataTableRow' : 'dataTableRowOver');?>">!-->
	    <tr>
		<td colspan=7><br>
			<table width="100%" align="left" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td width="60"></td>
				    <td colspan=7 valign="middle">
		<?php //echo '<a href="' . tep_href_link(FILENAME_ADD_SERVICES,"oID=$oID&step=1&mode=add") . '">' . tep_image_button('button_admin_add.gif',IMAGE_ADD_PRODUCT,'align=absmiddle') . '</a>';?>
	       <?php echo '<a href="' . tep_href_link(FILENAME_ADD_SERVICES,"oID=$oID&step=1&mode=add") . '">' . tep_image_button('button_add.gif',IMAGE_ADD_SERVICE,'align=absmiddle') . '</a>&nbsp;' ;
		   if($service_count>0){
		   		//echo '<a href="javascript:do_actions(\'service\',\'edit\');">' . tep_image_button('button_edit.gif',IMAGE_EDIT_SERVICE,'align=absmiddle')  .'</a>&nbsp;'.	
				 //'<a href="javascript:do_actions(\'service\',\'delete\');">' . tep_image_button('button_delete.gif',IMAGE_DELETE_SERVICE,'align=absmiddle')  . '</a>' ;
				echo '<a href="javascript:do_actions(\'service\',\'delete\');">' . tep_image_button('button_delete.gif',IMAGE_DELETE_SERVICE,'align=absmiddle')  . '</a>' ;
			}

	    //' <a href="' . tep_href_link(FILENAME_EDIT_ORDERS,"oID=$oID&action=add_product&mode=edit&id=$orders_products_id") . '">' . tep_image_button('button_edit.gif',IMAGE_EDIT_PRODUCT,'align=absmiddle')  .
	    //'<a href="' . tep_href_link(FILENAME_EDIT_ORDERS,'oID=' . $oID . "&action=delete_multiple_item&id=$orders_products_id") . '">' . tep_image_button('button_delete.gif',IMAGE_DELETE_PRODUCT,'align=absmiddle')  . '</a>';
	 ?>		       </td>
	 			</tr>
			</table>
		 </td>		
	</tr>
	</table><td></tr>
	<?php tep_content_title_bottom(); ?>
   <!-- end service entry -->
	<!-- Begin Order Total Block -->
	<tr>
		<td class="contentTitle"><?php echo tep_draw_separator('pixel_trans.gif', '1', '2'); ?></td>
	</tr>
	  <tr>
	    <td align=right>
	    	<table border="0" cellspacing="2" cellpadding="2" width=100% class=dataTablerowover>
		<tr>
	    	<td align='right'>
	    	<table border="0" cellspacing="2" cellpadding="2" align=right width=30%>
<?php
                $order_query=tep_db_query("SELECT currency,currency_value from " . TABLE_ORDERS . " where orders_id='" . $oID . "'");
				
                $order_info=tep_db_fetch_array($order_query);

		$totals_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$oID . "' order by sort_order");
		$order_detail->totals = array();
           $TotalsArray=array();
                while($totals=tep_db_fetch_array($totals_query)){
		   if ($totals['class']=='ot_subtotal'){
		      $TotalsArray[]=array('title'=>TEXT_PRESENT_SUBTOTAL,'value'=>$currencies->format($totals['value'], true,$order_info['currency'], $order_info['currency_value']));
		      $TotalsArray[]=array('title'=>TEXT_UPDATED_SUBTOTAL,'value'=>'<b><span id="u_st">' . $currencies->format(($RunningSubTotal), true,$order_info['currency'], $order_info['currency_value']) . '</span></b>');
		   }
		   else if ($totals['class']=='ot_tax'){
		      $TotalsArray[]=array('title'=>TEXT_PRESENT_TAX,'value'=>$currencies->format($totals['value'], true,$order_info['currency'], $order_info['currency_value']));
		      $TotalsArray[]=array('title'=>TEXT_UPDATED_TAX,'value'=>'<b><span id="u_tx">' . $currencies->format(($RunningTax), true,$order_info['currency'], $order_info['currency_value']) . '</span></b>');
		   }
		   else if ($totals['class']=='ot_shipping'){
		      $TotalsArray[]=array('title'=>TEXT_PRESENT_SHIPPING,'value'=>$currencies->format($totals['value'], true,$order_info['currency'], $order_info['currency_value']));
		      $TotalsArray[]=array('title'=>TEXT_UPDATED_SHIPPING,'value'=>'<b><span id="u_sh">' . $currencies->format($totals['value'], true,$order_info['currency'], $order_info['currency_value']) . '</span></b>');
		   }
		   else if ($totals['class']=='ot_total'){
		      $TotalsArray[]=array('title'=>TEXT_PRESENT_TOTAL,'value'=>$currencies->format($totals['value'], true,$order_info['currency'], $order_info['currency_value']));
		      $TotalsArray[]=array('title'=>TEXT_UPDATED_TOTAL,'value'=>'<b><span id="u_tl">' . $currencies->format(($Total), true,$order_info['currency'], $order_info['currency_value'])  . '</span></b>');
		   }
		}   
		for($icnt=0;$icnt<sizeof($TotalsArray);$icnt++){
		?>
		    <tr><td class=main align=right><?php echo $TotalsArray[$icnt]['title'];?></td>
		        <td class=smallText align=right><?php echo $TotalsArray[$icnt]['value'];?></td>
		    </tr>
                    <tr><td><?php if ($icnt%2==1) echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
		<?php 
		}
		echo tep_draw_hidden_field('products_type',$product_type);
		if ($products_check>0)
		  echo tep_draw_hidden_field('products_check','valid');
		else
		  echo tep_draw_hidden_field('products_check','invalid');
		  
		  // hidden values for checking if multiple attendees is empty
		  echo '<input type="hidden" name="multiple_attendees" value="' . ($edit_attendees?'1':'0') . '">';
		  echo '<input type="hidden" name="valid_attendees" value="' . ($edit_cart->check_attendees()?'1':'0') . '">';
?>
	    	</table>
	    	</td>
	    	</tr>
	    	</table>
	    </td>
	  </tr>
	  	<tr>
		<td class="contentTitle"><?php echo tep_draw_separator('pixel_trans.gif', '1', '2'); ?></td>
	</tr>

	<!-- End Order Total Block -->
<?php } ?>
<?php if ($step==5) {  ?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><td class="main"><table border="0" cellspacing="2" cellpadding="2" class="formarea" width=60%><tr>
	<tr bgcolor=white>
	   <td class="main"><?php echo '<b>' . TEXT_CURRENT_STATUS . '</b>' ;?></td></tr>
	<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
        <tr>
        <td class="main"><table border="1" cellspacing="0" cellpadding="5" width=100%>
          <tr>
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_DATE_ADDED; ?></b></td>
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_CUSTOMER_NOTIFIED; ?></b></td>
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_STATUS; ?></b></td>
            <?php if($CommentsWithStatus) { ?>
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_COMMENTS; ?></b></td>
            <?php } ?>
          </tr>
<?php
    $orders_history_query = tep_db_query("select * from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . tep_db_prepare_input($oID) . "' order by date_added");
    if (tep_db_num_rows($orders_history_query)) {
      while ($orders_history = tep_db_fetch_array($orders_history_query)) {
        echo '          <tr>' . "\n" .
             '            <td class="smallText" align="center">' . format_date($orders_history['date_added']) . '</td>' . "\n" .
             '            <td class="smallText" align="center">';
        if ($orders_history['customer_notified'] == '1') {
          echo tep_image(DIR_WS_ICONS . 'tick.gif', ICON_TICK) . "</td>\n";
        } else {
          echo tep_image(DIR_WS_ICONS . 'cross.gif', ICON_CROSS) . "</td>\n";
        }
        echo '            <td class="smallText">' . $orders_status_array[$orders_history['orders_status_id']] . '</td>' . "\n";
        
        if($CommentsWithStatus) {
        echo '            <td class="smallText">' . nl2br(tep_db_output($orders_history['comments'])) . '&nbsp;</td>' . "\n";
        }
        
        echo '          </tr>' . "\n";
      }
    } else {
        echo '          <tr>' . "\n" .
             '            <td class="smallText" colspan="5">' . TEXT_NO_ORDER_HISTORY . '</td>' . "\n" .
             '          </tr>' . "\n";
    }
?>
        </table></td>
      </tr>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
      </tr>
      <tr bgcolor=white>
	<td class="main"><b><?php echo TEXT_MODIFY_STATUS; ?></b></td>
      </tr>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
      <tr><td class="main"><table border="1" cellspacing="0" cellpadding="5" width=100%>
        <tr><td class="main"><table border="0" cellspacing="0" cellpadding="5" width=100%><tr>
           <td class="main"><b><?php echo ENTRY_STATUS; ?></b> 
	                    <?php echo tep_draw_pull_down_menu('status', $orders_statuses, $order_detail->info['orders_status']); ?>
                            <b><?php echo ENTRY_NOTIFY_CUSTOMER; ?></b> <?php echo tep_draw_checkbox_field('notify', '', true); ?>
          <?php if($CommentsWithStatus) { ?>
                <b><?php echo ENTRY_NOTIFY_COMMENTS; ?></b> <?php echo tep_draw_checkbox_field('notify_comments', '', true); ?>
          <?php } ?></td>
	</tr>
	<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	</tr>
      <tr>
        <td class="main"><b><?php echo TABLE_HEADING_COMMENTS; ?></b></td>
      </tr>

	<tr>
	<td class="main">
	<?
	if($CommentsWithStatus) {
		echo tep_draw_textarea_field('comments', 'soft', '60', '5');
	}
	else
	{
		echo tep_draw_textarea_field('comments', 'soft', '60', '5', $order_detail->info['comments']);
	}
	?>
	</td>
	</tr>
        </table></td></tr></table></td>
      </tr></table></td></tr>
	<tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
	</tr>
  <?php } ?>
	
    <tr>
	<script language="javascript">
		var submitProcessFlag=false;
		function submitPayment(){
			var select_payment='';
			var error_result="";
			var frm=document.edit_order;
			if (submitProcessFlag){
				alert("<?php echo addslashes(TEXT_FORM_SUBMITTED);?>");
				return;
			}
			submitProcessFlag=true;
			frm.button_update.src="<?php echo DIR_WS_LANGUAGES . $language . '/images/buttons/button_process.gif';?>";
			/*if (frm.payment[0]){ 
				for (icnt=0;icnt<frm.payment.length;icnt++){
					if (frm.payment[icnt].checked==true){ select_payment=frm.payment[icnt].value;break;}
				}
			} else {
				if (frm.payment.checked) select_payment=frm.payment.value;
			}*/
			//if (select_payment=='') error_result="<?php echo tep_db_input(ERR_SELECT_PAYMENT); ?>";
			if (error_result!=""){
				submitProcessFlag=false;
				document.edit_order.button_update.src="<?php echo DIR_WS_LANGUAGES . $language . '/images/buttons/button_continue.gif';?>";
				alert(error_result);
				return;
			}
			document.edit_order.submit();
		}
	</script>
  <table align="right" width="15%" cellpadding="2" cellspacing="2" border="0">
   <tr>
 	<td align='left' valign="top" class="main" nowrap="nowrap" width="100%">
	   <?php  
	     $type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'';
	   if ($step>1) echo '<a href="' . tep_href_link(FILENAME_EDIT_ORDERS,'oID=' . $oID . '&step=' . ($type=='E'?2:$step-1)) . '">' . tep_image_button('button_back.gif',IMAGE_BACK) . '</a>';
	     ?> </td>
		 <?php  if ($step==4){ ?> 
		  <td align="left" valign="top" class="main" id="update">
			<?php 
	        if (sizeof($selection)>0 && ($pay_type=='refund' || $pay_type=='getamount')) { 
	          echo '&nbsp' . tep_image_button('button_continue.gif',IMAGE_UPDATE,'style="cursor:pointer;cursor:hand" onClick="javascript:submitPayment();" name="button_update"');
		?> </td> <?php } else if ($update_details) { ?>
				<td valign="top" align="left" class="main" nowrap="nowrap">
			 <?php echo '&nbsp<a href="javascript:updateDetail()">' . tep_image_button("button_continue.gif",IMAGE_UPDATE_CHANGES) . '</a>';
			 }?> 
		  </td><?php
	      }
		   else {?> 
		   <td valign="top" align="left" class="main" nowrap="nowrap">
	          <?php echo '&nbsp' . tep_image_submit('button_continue.gif',IMAGE_CONTINUE); ?> 
	       </td>
		  <?php }
	   ?> 
  </tr>	
 </table> 
	
      </tr><table>	  
      </form>
<?php
  }
 ?>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?
  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function    : tep_get_country_id
  //
  // Arguments   : country_name		country name string
  //
  // Return      : country_id
  //
  // Description : Function to retrieve the country_id based on the country's name
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_get_country_id($country_name) {

    $country_id_query = tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_name = '" . $country_name . "'");

    if (!tep_db_num_rows($country_id_query)) {
      return 0;
    }
    else {
      $country_id_row = tep_db_fetch_array($country_id_query);
      return $country_id_row['countries_id'];
    }
  }

  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function    : tep_get_country_iso_code_2
  //
  // Arguments   : country_id		country id number
  //
  // Return      : country_iso_code_2
  //
  // Description : Function to retrieve the country_iso_code_2 based on the country's id
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_get_country_iso_code_2($country_id) {

    $country_iso_query = tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'");

    if (!tep_db_num_rows($country_iso_query)) {
      return 0;
    }
    else {
      $country_iso_row = tep_db_fetch_array($country_iso_query);
      return $country_iso_row['countries_iso_code_2'];
    }
  }

  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function    : tep_get_zone_id
  //
  // Arguments   : country_id		country id string
  //               zone_name		state/province name
  //
  // Return      : zone_id
  //
  // Description : Function to retrieve the zone_id based on the zone's name
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_get_zone_id($country_id, $zone_name) {

    $zone_id_query = tep_db_query("select * from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_name = '" . $zone_name . "'");

    if (!tep_db_num_rows($zone_id_query)) {
      return 0;
    }
    else {
      $zone_id_row = tep_db_fetch_array($zone_id_query);
      return $zone_id_row['zone_id'];
    }
  }
  
  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function    : tep_field_exists
  //
  // Arguments   : table	table name
  //               field	field name
  //
  // Return      : true/false
  //
  // Description : Function to check the existence of a database field
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_field_exists($table,$field) {

    $describe_query = tep_db_query("describe $table");
    while($d_row = tep_db_fetch_array($describe_query))
    {
      if ($d_row["Field"] == "$field")
      return true;
    }


    return false;
  }

  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function    : tep_html_quotes
  //
  // Arguments   : string	any string
  //
  // Return      : string with single quotes converted to html equivalent
  //
  // Description : Function to change quotes to HTML equivalents for form inputs.
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_html_quotes($string) {
    return str_replace("'", "&#39;", $string);
  } 

  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function    : tep_html_unquote
  //
  // Arguments   : string	any string
  //
  // Return      : string with html equivalent converted back to single quotes
  //
  // Description : Function to change HTML equivalents back to quotes
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_html_unquote($string) {
    return str_replace("&#39;", "'", $string);
  }
  function sbs_get_countries($countries_id = '', $with_iso_codes = false) {
    $countries_array = array();
    if ($countries_id) {
      if ($with_iso_codes) {
        $countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "' order by countries_name");
        $countries_values = tep_db_fetch_array($countries);
        $countries_array = array('countries_name' => $countries_values['countries_name'],
                                 'countries_iso_code_2' => $countries_values['countries_iso_code_2'],
                                 'countries_iso_code_3' => $countries_values['countries_iso_code_3']);
      } else {
        $countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'");
        $countries_values = tep_db_fetch_array($countries);
        $countries_array = array('countries_name' => $countries_values['countries_name']);
      }
    } else {
      $countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name");
      while ($countries_values = tep_db_fetch_array($countries)) {
        $countries_array[] = array('countries_id' => $countries_values['countries_id'],
                                   'countries_name' => $countries_values['countries_name']);
      }
    }

    return $countries_array;
  } 
function sbs_get_country_list($name, $selected = '', $parameters = '') { 
   $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT)); 
   $countries = sbs_get_countries(); 
   $size = sizeof($countries); 
   for ($i=0; $i<$size; $i++) { 
     $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']); 
   } 

   return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters); 
}
function tep_get_title($ind)
{
	switch($ind)
	{
		case 0:
			return TEXT_HEADING_PRODUCTS;
			break;
		case 1:
			return TEXT_HEADING_EVENTS;
			break;
		case 2:
			return TEXT_HEADING_SUBSCRIPTIONS;
			break;
		case 3:
			return TEXT_HEADING_SERVICES;
			break;
	}
}
function content_title_top($module,$payment_id,$funname='false',$hide_prev=false,$show_hidden=false,$params="",$align=false,$expand=0) {
		
	$title=$module;
	$heding=$title;
  	$title=str_replace(" ","_",$title);
  	$title=str_replace("\"","",$title);
	$title=str_replace("'","",$title);
  	$title=trim($title);
	 ?>

		<tr>
			<td valign="top" colspan="2">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr height="20"><td><table cellpadding="2" cellspacing="0" border="0" width="100%">
					<!-- <td><?php echo $title; ?></td><td id='img_<?php echo $title;?>' style="cursor:hand" onClick="javascript:toggle_panel(<?php echo '\'' . $title .'\',\''. $funname.'\',\'' . $hide_prev . '\',\''. $expand . '\');' . $params;?>"><?php echo $heding ;?></td> -->
					<tr><td class="main"><?php echo $module; ?></td><td align="right" id='img_<?php echo $title;?>' style="cursor:hand" onClick="javascript:toggle_panel(<?php echo '\'' . $title .'\',\''. $funname.'\',\'' . $hide_prev . '\',\''. $expand . '\');' . $params;?>"><?php echo tep_draw_radio_field('payment_select', $payment_id,false,' disabled="disabled" ') ;?></td></tr>
				</table></td></tr>	
				<tr height="5">
					<td></td>
				</tr>
	<?php if($show_hidden) { ?>
			<tr id='panel_<?php echo $title; ?>' style="display:none">
	<?php }	else { 	?>
			<tr id='panel_<?php echo $title; ?>'>
	<?php }
			if($align) {	?>
			  <td colspan="2">
	<?php 	} else {	?>
			  <td>
	<?php }  ?>			
				<table border="0" cellpadding="0" cellspacing="0" width="100%"> 
<?php }
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>