<?php
/*
osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	tep_get_last_access_file();              //Added for Categories Description 1.5  
	require('includes/functions/events_description.php');
	require('includes/functions/events_tree.php');
	require('includes/functions/subscription_tree.php');
	//End Categories Description 1.5 
	
	require(DIR_WS_CLASSES . 'currencies.php');
	$currencies = new currencies();
	$subscription_array=tep_get_subscription_array_single();
	$server_date = getServerDate(true);	
	$content="";
	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	$command=isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'';
	if($command=='fetch_customer_details'){
	echo 'fetch_customer_details^^';
	echo '<select name="sel_customers" id="sel_customers" onchange="javascript:do_submit(this.value);" class="inputNormal" onblur="javascript:toggle_focus(this,1);" onfocus="javascript:toggle_focus(this,2);">';
	echo '<option value="-1">-- Select --</option>';
		$customer_query=tep_db_query("select o.customers_id,o.customers_name from ".TABLE_ORDERS." o, ".TABLE_ORDERS_PRODUCTS." op, ". TABLE_CUSTOMERS ." c where c.customers_id=o.customers_id and o.orders_id=op.orders_id and op.products_type='V' and lcase(o.payment_method) like '%internal only%' group by o.customers_id");
		while($customer_result=tep_db_fetch_array($customer_query)){
			//$content.= $customer_result['customers_id'] .":" . $customer_result['customers_name'] ."#";
		echo '<option value="'.$customer_result['customers_id'].'">'.$customer_result['customers_name'].'</option>';
		}
	echo '</select>';
		//$content.="#*#";
		//echo $content;
		exit;
	} else if($command=="fetch_service_details"){
		echo 'fetch_service_details^^';
		$customer_id=(isset($HTTP_GET_VARS['customers_id'])?$HTTP_GET_VARS['customers_id']:'');
		echo '<select name="sel_services" id="sel_services" class="inputNormal" onblur="javascript:toggle_focus(this,1);" onfocus="javascript:toggle_focus(this,2);">';
		echo '<option value="-1">-- Select --</option>';
		$service_query=tep_db_query("select op.products_id,op.products_name from ". TABLE_ORDERS ." o, ".TABLE_ORDERS_PRODUCTS ." op, ".TABLE_SERVICES." s, ".TABLE_SERVICES_DESCRIPTION ." sd where s.service_id=sd.service_id and sd.service_id=op.products_id and o.orders_id=op.orders_id and op.products_type='V' and lcase(o.payment_method) like '%internal only%' and o.customers_id='".(int)$customer_id."' group by s.service_id");
		while($service_result=tep_db_fetch_array($service_query)){
			//$content.= $service_result['products_id'] .":" . $service_result['products_name'] ."^";
			echo '<option value="'.$service_result['products_id'].'">'.$service_result['products_name'].'</option>';
		}
		//	$content.="^*^";
		echo '</select>';
		exit;
	}
if (tep_not_null($action)) {
	switch ($action) {
		case 'setflag':
			if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
				if (isset($HTTP_GET_VARS['eID'])) {
					tep_set_event_status($HTTP_GET_VARS['eID'], $HTTP_GET_VARS['flag']);
				}
			}
			
			tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $HTTP_GET_VARS['ecPath'] . '&eID=' . $HTTP_GET_VARS['eID']));
			break;

//Added for Categories Description 1.5
		case 'new_events_category':
		case 'edit_events_category':
			if (ALLOW_CATEGORY_DESCRIPTIONS == 'true')
				$HTTP_GET_VARS['action']=$HTTP_GET_VARS['action'] . '_ACD';
			break;
//End Categories Description 1.5

		case 'insert_events_category':
		case 'update_events_category':
				
			//Added for Categories Description 1.5
			
			if ( ($HTTP_POST_VARS['edit_x']) || ($HTTP_POST_VARS['edit_y']) ) {
				$HTTP_GET_VARS['action'] = 'edit_events_category_ACD';
			} else {
			
			//End Categories Description 1.5
			
				if (isset($HTTP_POST_VARS['events_categories_id'])) $events_categories_id = tep_db_prepare_input($HTTP_POST_VARS['events_categories_id']);
			
				//Added for Categories Description 1.5
				if ($events_categories_id == '') {
					$events_categories_id = tep_db_prepare_input($HTTP_GET_VARS['ecID']);
				}
				//End Categories Description 1.5

				$sort_order = ((int)$HTTP_POST_VARS['sort_order']!=0?tep_db_prepare_input($HTTP_POST_VARS['sort_order']):1);
				
				$sql_data_array = array('sort_order' => $sort_order);
				
				if ($action == 'insert_events_category') {
					$insert_sql_data = array(	'parent_id' => $current_events_category_id,
												'date_added' =>  $server_date );

				
					$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				
					tep_db_perform(TABLE_EVENTS_CATEGORIES, $sql_data_array);
				
					$events_categories_id = tep_db_insert_id();
					
				} elseif ($action == 'update_events_category') {
					
					$update_sql_data = array('last_modified' =>  $server_date);
				
					$sql_data_array = array_merge($sql_data_array, $update_sql_data);
				
					tep_db_perform(TABLE_EVENTS_CATEGORIES, $sql_data_array, 'update', "events_categories_id = '" . (int)$events_categories_id . "'");
				}

				$languages = tep_get_languages();
				for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
					$events_categories_name_array = $HTTP_POST_VARS['events_categories_name'];
				
					$language_id = $languages[$i]['id'];
				
					$sql_data_array = array('events_categories_name' => tep_db_prepare_input($events_categories_name_array[$language_id]));
				
				//Added for Categories Description 1.5
					if (ALLOW_CATEGORY_DESCRIPTIONS == 'true') {
						$sql_data_array = array('events_categories_name' => tep_db_prepare_input($HTTP_POST_VARS['events_categories_name'][$language_id]),
												'events_categories_heading_title' => tep_db_prepare_input($HTTP_POST_VARS['events_categories_heading_title'][$language_id]),
												'events_categories_description' => tep_db_prepare_input($HTTP_POST_VARS['events_categories_description'][$language_id]));
					}
				//End Categories Description 1.5

					if ($action == 'insert_events_category') {
						$insert_sql_data = array(	'events_categories_id' => $events_categories_id,
													'language_id' => $languages[$i]['id']);
					
						$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
					
						tep_db_perform(TABLE_EVENTS_CATEGORIES_DESCRIPTION, $sql_data_array);
					} elseif ($action == 'update_events_category') {
						tep_db_perform(TABLE_EVENTS_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "events_categories_id = '" . (int)$events_categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
					}
				}
				//Code commented out for Categories Description 1.5
				//        if ($events_categories_image = new upload('events_categories_image', DIR_FS_CATALOG_IMAGES)) {
				//          tep_db_query("update " . TABLE_EVENTS_CATEGORIES . " set events_categories_image = '" . //tep_db_input($events_categories_image->filename) . "' where events_categories_id = '" . (int)$events_categories_id . "'");
				//        }
				//Added the following to replacce above code
				if (ALLOW_CATEGORY_DESCRIPTIONS == 'true') {
					tep_db_query("update " . TABLE_EVENTS_CATEGORIES . " set events_categories_image = '" . $HTTP_POST_VARS['events_categories_image'] . "' where events_categories_id = '" .  (int)tep_db_input($events_categories_id) . "'");
					$events_categories_image = '';
				} else {
					if ($events_categories_image = new upload('events_categories_image', DIR_FS_CATALOG_IMAGES)) {
						tep_db_query("update " . TABLE_EVENTS_CATEGORIES . " set events_categories_image = '" . tep_db_input($events_categories_image->filename) . "' where events_categories_id = '" . (int)$events_categories_id . "'");
					}
				}
				//End Categories Description 1.5

				if (isset($ecPath))
					tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $events_categories_id));
				else
					tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath));

				//Added for Categories Description 1.5
        	}
			//End Categories Description 1.5
			break;
		case 'delete_events_category_confirm':
			if (isset($HTTP_POST_VARS['events_categories_id'])) {
				$events_categories_id = tep_db_prepare_input($HTTP_POST_VARS['events_categories_id']);
				
				$events_categories = tep_get_events_category_tree($events_categories_id, '', '0', '', true);
				$events = array();
				$events_delete = array();
				
				for ($i=0, $n=sizeof($events); $i<$n; $i++) {
					$events_ids_query = tep_db_query("SELECT events_id from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_categories_id = '" . (int)$events_categories[$i]['id'] . "'");
				
					while ($events_ids = tep_db_fetch_array($events_ids_query)) {
						$events[$event_ids['events_id']]['events_categories'][] = $events_categories[$i]['id'];
					}
				}

				reset($events);
				while (list($key, $value) = each($events)) {
					$events_category_ids = '';
				
					for ($i=0, $n=sizeof($value['events_categories']); $i<$n; $i++) {
						$events_category_ids .= "'" . (int)$value['events_categories'][$i] . "', ";
					}
					$events_category_ids = substr($events_category_ids, 0, -2);
				
					$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$key . "' and events_categories_id not in (" . $events_category_ids . ")");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') {
						$events_delete[$key] = $key;
					}
				}

				// removing categories can be a lengthy process
				tep_set_time_limit(0);
				for ($i=0, $n=sizeof($events_categories); $i<$n; $i++) {
					tep_remove_events_category($events_categories[$i]['id']);
				}

				reset($events_delete);
				while (list($key) = each($events_delete)) {
					tep_remove_event($key);
				}
			}
		
			tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath));
			break;
			case 'delete_event_confirm':
				if (isset($HTTP_POST_VARS['events_id']) && isset($HTTP_POST_VARS['events_categories']) && is_array($HTTP_POST_VARS['events_categories'])) {
					$event_id = tep_db_prepare_input($HTTP_POST_VARS['events_id']);
					$events_categories = $HTTP_POST_VARS['events_categories'];
					for ($i=0, $n=sizeof($events_categories); $i<$n; $i++) {
						tep_db_query("delete from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$event_id . "' and events_categories_id = '" . (int)$events_categories[$i] . "'");
					}
			
					$events_categories_query = tep_db_query("SELECT count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$event_id . "'");
					$events_categories = tep_db_fetch_array($events_categories_query);
			
					if ($events_categories['total'] == '0') {
						tep_remove_event($event_id);
					}
				}
				tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath));
				break;
			case 'move_events_category_confirm':
				if (isset($HTTP_POST_VARS['events_categories_id']) && ($HTTP_POST_VARS['events_categories_id'] != $HTTP_POST_VARS['move_to_events_category_id'])) {
						$events_categories_id = tep_db_prepare_input($HTTP_POST_VARS['events_categories_id']);
						$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_events_category_id']);
			
						$path = explode('_', tep_get_generated_events_category_path_ids($new_parent_id)); 

						if (in_array($events_categories_id, $path)) {
							$messageStack->add_session(ERROR_CANNOT_MOVE_EVENTS_CATEGORY_TO_PARENT, 'error');
						
							tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $events_categories_id));
						} else {
							tep_db_query("update " . TABLE_EVENTS_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified ='". $server_date ."' where events_categories_id = '" . (int)$events_categories_id . "'");
			
							
							tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $new_parent_id . '&ecID=' . $events_categories_id));
						}
				}
				break;
			case 'move_event_confirm':
				$events_id = tep_db_prepare_input($HTTP_POST_VARS['events_id']);
				$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_events_category_id']);
				if ($new_parent_id!=0)
				{
					$duplicate_check_query = tep_db_query("SELECT count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$events_id . "' and events_categories_id = '" . (int)$new_parent_id . "'");
					$duplicate_check = tep_db_fetch_array($duplicate_check_query);
					if ($duplicate_check['total'] < 1) tep_db_query("update " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " set events_categories_id = '" . (int)$new_parent_id . "' where events_id = '" . (int)$events_id . "' and events_categories_id = '" . (int)$current_events_category_id . "'");
		

					tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $new_parent_id . '&eID=' . $events_id));
				}
        		break;
			case 'insert_event':
			case 'update_event':
				//PR Algozone: copy image only if modified
			
				$events_image = new upload('events_image');
				$events_image->set_destination(DIR_FS_CATALOG_IMAGES);
				if ($events_image->parse() && $events_image->save()) {
					$events_image_name = $events_image->filename;
				} else {
					$events_image_name = (isset($HTTP_POST_VARS['events_previous_image']) ? $HTTP_POST_VARS['events_previous_image'] : '');
				}

				if (isset($HTTP_POST_VARS['edit_x']) || isset($HTTP_POST_VARS['edit_y'])) {
					$action = 'new_event';
				} else {
					if (isset($HTTP_GET_VARS['eID'])) $events_id = tep_db_prepare_input($HTTP_GET_VARS['eID']);
						$events_date_available = tep_db_prepare_input($HTTP_POST_VARS['events_date_available']);
						$events_date_available =tep_convert_date_raw($events_date_available);
						if($events_date_available=='') $events_date_available=getServerDate();
				
						$hours=(int)$HTTP_POST_VARS['start_time_hours'];
						$minute=(int)$HTTP_POST_VARS['start_time_minutes'];
						$day_session=$HTTP_POST_VARS['start_time_session'];
						if ($day_session=='PM' && $hours<12) $hours=$hours+12;
						
						$start_time=$hours . ":" . $minute ;

						$hours=(int)$HTTP_POST_VARS['end_time_hours'];
						$minute=(int)$HTTP_POST_VARS['end_time_minutes'];
						$day_session=$HTTP_POST_VARS['end_time_session'];
						if ($day_session=='PM' && $hours<12) $hours=$hours+12;
						$end_time=$hours . ":" . $minute ;
	  
						//$events_fees=(double)$HTTP_POST_VARS['events_fees_net'];
						//$events_tax=(int)$HTTP_POST_VARS['events_tax_class_id'];
						$session_gaps=(isset($HTTP_POST_VARS["session_gaps"])?$HTTP_POST_VARS["session_gaps"]:'N');
						$session_reduction=(isset($HTTP_POST_VARS["session_reduction"])?$HTTP_POST_VARS["session_reduction"]:'N');
						$session_style=(isset($HTTP_POST_VARS["session_style"])?$HTTP_POST_VARS["session_style"]:'S');
						$rate_type=(isset($HTTP_POST_VARS["instructors_rate_type"])?$HTTP_POST_VARS["instructors_rate_type"]:'GP');
						$rate=(isset($HTTP_POST_VARS["instructors_rate"])?$HTTP_POST_VARS["instructors_rate"]:0);
						$base_rate=(isset($HTTP_POST_VARS["instructors_base_rate"])?$HTTP_POST_VARS["instructors_base_rate"]:0);
						$events_group_bookings=(isset($HTTP_POST_VARS["events_group_bookings"])?'Y':'N');
						$events_group_min=(int)$HTTP_POST_VARS["events_group_min"];
						$events_group_max=(int)$HTTP_POST_VARS["events_group_max"];
						$link_service=(isset($HTTP_POST_VARS['link_service'])?$HTTP_POST_VARS['link_service']:'L');
						$events_location=(isset($HTTP_POST_VARS['events_location'])?$HTTP_POST_VARS['events_location']:'');
						$service_id=(isset($HTTP_POST_VARS['sel_services'])?$HTTP_POST_VARS['sel_services']:'');
						$events_max_reserve=(isset($HTTP_POST_VARS['events_max_reserve'])?tep_db_prepare_input($HTTP_POST_VARS['events_max_reserve']):'0');
						
						if($link_service=='S')
							$events_location='';
						else
							$service_id='';	
						
						if($events_max_reserve=='') $events_max_reserve='0';	
						
						$events_wait_list=$HTTP_POST_VARS['events_wait_list'];
						$events_forward_period=$HTTP_POST_VARS['events_forward_period'];
							
						if ($events_wait_list!='Y') $events_wait_list='N';
						if ($events_forward_period!='Y') $events_forward_period='N';
						
						$event_fees_net=$HTTP_POST_VARS['events_fees_net'];
						if($event_fees_net=='') $event_fees_net='0';
						
						$events_overbook_reserve=$HTTP_POST_VARS['events_overbook_reserve'];
						if($events_overbook_reserve=='') $events_overbook_reserve='0';
						
						$subscription_overbook_reserve=$HTTP_POST_VARS['subscription_overbook_reserve'];
						if($subscription_overbook_reserve=='') $subscription_overbook_reserve='0';
						
						$event_forward_length=$HTTP_POST_VARS['events_forward_length'];
						if($event_forward_length=='') $event_forward_length='0';
						
						$event_pending_period=$HTTP_POST_VARS['events_pending_period'];
						if($event_pending_period=='') $event_pending_period='0';
						
						$events_renewal_end=$HTTP_POST_VARS['events_renewal_end'];
						if($events_renewal_end=='') $events_renewal_end='0';
						
						if($service_id=='') $service_id='0';

						$sql_data_array = array('events_date_available' => $events_date_available,
												'events_start_time'=>$start_time,
												'events_end_time'=>$end_time,
												'events_location'=>$events_location,
												'events_instructor'=>tep_db_prepare_input($HTTP_POST_VARS['events_instructor']),
												'events_backup_instructor'=>tep_db_prepare_input($HTTP_POST_VARS['events_backup_instructor']),				  
												'events_fees'=>tep_db_prepare_input($event_fees_net),
												'events_tax_class_id'=>tep_db_prepare_input($HTTP_POST_VARS['events_tax_class_id']),
												'events_max_reserve' => $events_max_reserve,
												'events_overbook_reserve'=>tep_db_prepare_input($events_overbook_reserve),
												'subscription_overbook_reserve'=>tep_db_prepare_input($subscription_overbook_reserve),
												
												'events_payment'=>tep_db_prepare_input($HTTP_POST_VARS['events_payment']),
												'refund_percentage1'=>tep_db_prepare_input($HTTP_POST_VARS['refund_percentage1']),
												'refund_percentage2'=>tep_db_prepare_input($HTTP_POST_VARS['refund_percentage2']),
												'refund_percentage3'=>tep_db_prepare_input($HTTP_POST_VARS['refund_percentage3']),
												'events_status' => tep_db_prepare_input($HTTP_POST_VARS['events_status']),
												'events_wait_list'=>tep_db_prepare_input($events_wait_list),
												'priority_vip'=>tep_db_prepare_input($HTTP_POST_VARS['priority_vip']),
												'priority_firstcome'=>tep_db_prepare_input($HTTP_POST_VARS['priority_firstcome']),
												'priority_custom'=>tep_db_prepare_input($HTTP_POST_VARS['priority_custom']),
												'priority_question'=>tep_db_prepare_input($HTTP_POST_VARS['priority_question']),
												'waitsize_vip'=>tep_db_prepare_input($HTTP_POST_VARS['waitsize_vip']),
												'waitsize_firstcome'=>tep_db_prepare_input($HTTP_POST_VARS['waitsize_firstcome']),
												'waitsize_custom'=>tep_db_prepare_input($HTTP_POST_VARS['waitsize_custom']),
												'events_conditions'=>tep_db_prepare_input($HTTP_POST_VARS['events_conditions']),
												'waitfee_vip'=>tep_db_prepare_input($HTTP_POST_VARS['waitfee_vip']),
												'waitfee_firstcome'=>tep_db_prepare_input($HTTP_POST_VARS['waitfee_firstcome']),
												'waitfee_custom'=>tep_db_prepare_input($HTTP_POST_VARS['waitfee_custom']),
												'events_forward_period'=>tep_db_prepare_input($events_forward_period),
												'events_forward_length'=>tep_db_prepare_input($event_forward_length),
												'events_renewal_start'=>tep_db_prepare_input($HTTP_POST_VARS['events_renewal_start']),
												'events_pending_period'=>tep_db_prepare_input($event_pending_period),
												'events_renewal_end'=>tep_db_prepare_input($events_renewal_end),
												'session_gaps'=>tep_db_prepare_input($session_gaps),
												'session_reduction'=>tep_db_prepare_input($session_reduction),
												'session_style'=>tep_db_prepare_input($session_style),
												'instructors_rate_type'=>tep_db_prepare_input($rate_type),
												'instructors_rate'=>tep_db_prepare_input($rate),
												'instructors_base_rate'=>tep_db_prepare_input($base_rate),
												'events_group_bookings'=>tep_db_prepare_input($events_group_bookings),
												'events_group_min'=>tep_db_prepare_input($events_group_min),
												'events_group_max'=>tep_db_prepare_input($events_group_max),
												'link_service' => tep_db_prepare_input($link_service),
												'service_id' =>tep_db_prepare_input($service_id)
												);
						if (isset($events_image_name) && tep_not_null($events_image_name) && ($events_image_name != 'none')) {
							$sql_data_array['events_image'] = tep_db_prepare_input($events_image_name);
						}
						//echo $action;
						if ($action == 'insert_event') {
							$insert_sql_data = array('events_date_added' => $server_date);
						
							$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
						
							tep_db_perform(TABLE_EVENTS, $sql_data_array);
							$events_id = tep_db_insert_id();
							//$selected_vehicle_ids = $HTTP_POST_VARS['chkveh'];
								
					

						} elseif ($action == 'update_event') {
							$update_sql_data = array('events_last_modified' => $server_date);
						
							$sql_data_array = array_merge($sql_data_array, $update_sql_data);
						
							tep_db_perform(TABLE_EVENTS, $sql_data_array, 'update', "events_id = '" . (int)$events_id . "'");
							
							tep_db_query("delete from " . TABLE_EVENTS_TO_SUBSCRIPTIONS . " where events_id='" . (int)$events_id . "' ");
            
							if ((int)$HTTP_POST_VARS['old_max_reserve']!=(int)$HTTP_POST_VARS['events_max_reserve']){
								tep_check_waiting_list($events_id);}
							#PR Algozone: delete categories saved in the tables

							tep_db_query("delete from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '". (int)$events_id . "'");
				        }
						
								$subscription_categories_array_selected=$HTTP_POST_VARS['subscription_categories_ids'];
								if ($subscription_categories_array_selected)
								{
									foreach ($subscription_categories_array_selected as $current_sub_id)
									{	
										tep_db_query("insert into " . TABLE_EVENTS_TO_SUBSCRIPTIONS . " (events_id, subscription_id) values ('" . (int)$events_id . "', '" . $current_sub_id . "')");
										
									}
								}
								
						
						
						
					//echos("insert into " . TABLE_EVENTS_TO_SUBSCRIPTIONS . " (events_id, subscription_id) values ('" . (int)$events_id . "', '" . $subscription_categories_ids . "')");
					

						/*$message_query=tep_db_query("SELECT message_send from " . TABLE_EVENTS_MESSAGES . " where events_id='" . $events_id . "' and message_type='RNR'");
						if (tep_db_num_rows($message_query)>0)
							tep_db_query("UPDATE " . TABLE_EVENTS_MESSAGES . " set message_send='" . tep_db_input($HTTP_POST_VARS['renewal_period_start']) . "' where events_id='" . $events_id . "' and message_type='RNR'");
						else
							tep_db_query("INSERT into " . TABLE_EVENTS_MESSAGES . "(message_send,events_id,message_type) values('" . $HTTP_POST_VARS['renewal_period_start'] . "','" . $events_id . "','RNR')");
		
						$sms_message_query=tep_db_query("SELECT message_send from " . TABLE_EVENTS_SMS_MESSAGES . " where events_id='" . $events_id . "' and message_type='RNR'");
						if (tep_db_num_rows($sms_message_query)>0)
							tep_db_query("UPDATE " . TABLE_EVENTS_SMS_MESSAGES . " set message_send='" . tep_db_input($HTTP_POST_VARS['renewal_period_start']) . "' where events_id='" . $events_id . "' and message_type='RNR'");
						else
							tep_db_query("INSERT into " . TABLE_EVENTS_SMS_MESSAGES . "(message_send,events_id,message_type) values('" . $HTTP_POST_VARS['renewal_period_start'] . "','" . $events_id . "','RNR')");*/

						# create loop here to insert rows for multiple categories
						$selected_events_catids = $HTTP_POST_VARS['events_categories_ids'];
						if ($selected_events_catids)
						{
							foreach ($selected_events_catids as $current_events_category_id)
							{	
								tep_db_query("insert into " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " (events_id, events_categories_id) values ('" . $events_id . "', '" . $current_events_category_id . "')");
								$ecPath=$current_events_category_id;
							}
						}
						// subscription
						
							# get selected categories
	
		//$subscription_categories_array = tep_get_subscription_category_tree(); 
		//$subscription_array=tep_get_subscription_array_single(
		
	
		
		
		// select subscriptions
	$sql = "select su.subscription_id, sud.subscription_name from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION .
			" sud where su.subscription_id = sud.subscription_id and sud.language_id='" . (int)$languages_id . "' " . SUBSCRIPTION_CONDITION_STATUS . " order by subscription_name";
	$sql_result = tep_db_query($sql);
	$sub_array[]=array("id"=>-1,"text"=>TEXT_ALL_SUBSCRIPTIONS);
	while($row=tep_db_fetch_array($sql_result)) {
		$subscription_array[]=array("id"=>$row["subscription_id"],"text"=>$row["subscription_name"]);
	}
	mysql_free_result($sql_result);
					

						$languages = tep_get_languages();
						for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
							$language_id = $languages[$i]['id'];
					
							$sql_data_array = array('events_name' => tep_db_prepare_input($HTTP_POST_VARS['events_name'][$language_id]),
													'events_description' => tep_db_prepare_input($HTTP_POST_VARS['events_description'][$language_id]),
													'events_url' => tep_db_prepare_input($HTTP_POST_VARS['events_url'][$language_id]));
					
							if ($action == 'insert_event') {
								$insert_sql_data = array(	'events_id' => $events_id,
															'language_id' => $language_id);
							
								$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
							
								tep_db_perform(TABLE_EVENTS_DESCRIPTION, $sql_data_array);
							} elseif ($action == 'update_event') {
								tep_db_perform(TABLE_EVENTS_DESCRIPTION, $sql_data_array, 'update', "events_id = '" . (int)$events_id . "' and language_id = '" . (int)$language_id . "'");
							}
						}
			
				}
				tep_redirect(tep_href_link(FILENAME_EVENTS_MAINPAGE,'top=1&mPath=2'));
        		break;
      		case 'copy_to_confirm':
				if (isset($HTTP_POST_VARS['events_id']) && isset($HTTP_POST_VARS['events_categories_id'])) {
					$events_id = tep_db_prepare_input($HTTP_POST_VARS['events_id']);
					$events_categories_id = tep_db_prepare_input($HTTP_POST_VARS['events_categories_id']);
				
				if ($HTTP_POST_VARS['copy_as'] == 'link') {
					if ($events_categories_id != $current_events_category_id) {
						$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$events_id . "' and events_categories_id = '" . (int)$events_categories_id . "'");
						$check = tep_db_fetch_array($check_query);
						if ($check['total'] < '1') {
							tep_db_query("insert into " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " (events_id, events_categories_id) values ('" . (int)$events_id . "', '" . (int)$events_categories_id . "')");
						}
					} else {
						$messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_EVENTS_CATEGORY, 'error');
					}
				} elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
					  // This is for Diveabout
					$event_sql = "SELECT events_image, events_date_available, events_status, events_max_reserve,events_overbook_reserve,subscription_overbook_reserve,events_fees,events_tax_class_id,"
												. "events_start_time,events_end_time,events_instructor,events_backup_instructor,events_payment,refund_percentage1,refund_percentage2,refund_percentage3,events_location, "
												. "events_wait_list,priority_vip,priority_firstcome,priority_custom,priority_question,sessions_select_count,sessions_select_interval,sessions_date_count,waitsize_vip, "
												. "waitsize_firstcome,waitsize_custom,events_conditions,waitfee_vip,waitfee_firstcome,waitfee_custom,events_forward_period,events_forward_length,events_pending_period, "
												. "events_renewal_start,events_renewal_end ,session_gaps,session_reduction,session_style,instructors_rate_type,instructors_rate,instructors_base_rate, "
												. "events_group_bookings,events_group_min,events_group_max,link_service,service_id "
												. " from " . TABLE_EVENTS . " where events_id = '" . (int)$events_id . "'";
					$event_query = tep_db_query($event_sql);
					$event = tep_db_fetch_array($event_query);
					
					$insert_q = "insert into " . TABLE_EVENTS . " (events_image, events_date_added, events_date_available, events_status, events_max_reserve,"
																. " events_overbook_reserve,subscription_overbook_reserve,events_fees,events_tax_class_id,events_start_time,"
																. " events_end_time,events_instructor,events_backup_instructor,events_location,events_payment,"
																. " refund_percentage1,refund_percentage2,refund_percentage3,events_wait_list,priority_vip,"
																. " priority_firstcome,priority_custom,priority_question,sessions_select_count,sessions_select_interval, "
																. " sessions_date_count,waitsize_vip,waitsize_firstcome,waitsize_custom,events_conditions,"
																. " waitfee_vip,waitfee_firstcome,waitfee_custom,events_forward_period,events_forward_length,"
																. " events_pending_period,events_renewal_start,events_renewal_end,session_gaps,session_reduction,"
																. " session_style,instructors_rate_type,instructors_rate,instructors_base_rate,events_group_bookings,"
																. " events_group_min,events_group_max,link_service,service_id) "
																. " values ('" . tep_db_input($event['events_image']) . "','".  getServerDate(true) ."', '" . tep_db_input($event['events_date_available'])
																. "', '" . tep_db_input($event['events_status']) . "', '" . tep_db_input($event['events_max_reserve']) . "', '" . tep_db_input($event['events_overbook_reserve']) 
																. "', '" . tep_db_input($event['subscription_overbook_reserve'])  . "', '" . tep_db_input($event['events_fees']) . "', '" . tep_db_input($event['events_tax_class_id'])
																. "', '" .  tep_db_input($event['events_start_time']) . "', '" . tep_db_input($event['events_end_time']) . "', '" . tep_db_input($event['events_instructor'])
																. "', '" . tep_db_input($event['events_backup_instructor']) . "', '" . tep_db_input($event['events_location']) . "', '" . tep_db_input($event['events_payment'])
																.  "', '" . tep_db_input($event['refund_percentage1']) . "', '" . tep_db_input($event['refund_percentage2'])
																. "', '" . tep_db_input($event['refund_percentage3']) . "', '" . tep_db_input($event['events_wait_list']) . "', '" . tep_db_input($event['priority_vip'])
																. "', '" . tep_db_input($event['priority_firstcome']) . "','" . tep_db_input($event['priotity_custom']) . "','" . tep_db_input($event['priority_question'])
																. "', '" . tep_db_input($event['sessions_select_count']) . "', '" . tep_db_input($event['sessions_select_interval']) . "','" . tep_db_input($event['sessions_date_count'])
																. "', '" . tep_db_input($event['waitsize_vip']) . "', '" . tep_db_input($event['waitsize_firstcome']) . "', '" . tep_db_input($event['waitsize_custom'])
																. "', '" . tep_db_input($event['events_conditions']) . "', '" . tep_db_input($event['waitfee_vip']) . "', '" . tep_db_input($event['waitfee_firstcome'])
																. "', '" . tep_db_input($event['waitfee_custom']) . "', '" . tep_db_input($event['events_forward_period']) . "', '" . tep_db_input($event['events_forward_length'])
																. "', '" . tep_db_input($event['events_pending_period']) . "', '" . tep_db_input($event['events_renewal_start']) . "', '" . tep_db_input($event['events_renewal_end'])
																. "', '" . tep_db_input($event['session_gaps']) . "', '" . tep_db_input($event['session_reduction']) . "', '" . tep_db_input($event['session_style'])
																. "', '" . tep_db_input($event['instructors_rate_type']) . "', '" . tep_db_input($event['instructors_rate']) . "', '" . tep_db_input($event['instructors_base_rate'])
																. "', '" . tep_db_input($event['events_group_bookings']) . "', '" . tep_db_input($event['events_group_min']) . "', '" . tep_db_input($event['events_group_max'])
																. "', '" . tep_db_input($event['link_service']) . "','".tep_db_input($event['service_id'])."')";
					tep_db_query($insert_q);
					$dup_events_id = tep_db_insert_id();
					
		            if (isset($HTTP_POST_VARS['copy_messages'])){
						//copy the messages
						$message_query=tep_db_query("SELECT message_send,message_subject,message_reply_to,message_text,message_format,events_id,message_type from " . TABLE_EVENTS_MESSAGES . " where events_id='" . (int)$events_id . "'");
						while($message_result=tep_db_fetch_array($message_query)){
							$message_result["events_id"]=$dup_events_id;
							tep_db_perform(TABLE_EVENTS_MESSAGES,$message_result);
						}
						//copy the messages
						$message_query=tep_db_query("SELECT message_send,message_subject,message_text,events_id,message_type from " . TABLE_EVENTS_SMS_MESSAGES . " where events_id='" . (int)$events_id . "'");
						while($message_result=tep_db_fetch_array($message_query)){
							$message_result["events_id"]=$dup_events_id;
							tep_db_perform(TABLE_EVENTS_SMS_MESSAGES,$message_result);
						}
					}
					//copy surveys
					if (isset($HTTP_POST_VARS['copy_surveys'])){
						$survey_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS . " where events_id='" . (int)$events_id . "'");
						while($survey_result=tep_db_fetch_array($survey_query)){
							$old_survey_id=$survey_result["survey_id"];
							$survey_result["events_id"]=$dup_events_id;
							unset($survey_result["survey_id"]);
							tep_db_perform(TABLE_EVENTS_SURVEYS,$survey_result);
							$new_survey_id=tep_db_insert_id();
							$question_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . (int)$old_survey_id . "'");
							while($question_result=tep_db_fetch_array($question_query)){
								$old_question_id=$question_result["question_id"];
								$question_result["survey_id"]=$new_survey_id;
								unset($question_result["question_id"]);
								tep_db_perform(TABLE_EVENTS_SURVEYS_QUESTION,$question_result);
								$new_question_id=tep_db_insert_id();
								if ($question_result["question_type"]<=3){
									$choice_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_CHOICE . " where question_id='" . (int)$old_question_id . "'");
									while($choice_result=tep_db_fetch_array($choice_query)){
										$choice_result["question_id"]=$new_question_id;
										unset($choice_result["choice_id"]);
										tep_db_perform(TABLE_EVENTS_SURVEYS_CHOICE,$choice_result);
									}
								}
							}
						}
					}
					$description_query = tep_db_query("SELECT language_id, events_name, events_description,events_url from " . TABLE_EVENTS_DESCRIPTION . " where events_id = '" . (int)$events_id . "'");
					while ($description = tep_db_fetch_array($description_query)) {
						tep_db_query("insert into " . TABLE_EVENTS_DESCRIPTION . " (events_id, language_id, events_name, events_description, events_url, events_viewed) values ('" . (int)$dup_events_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['events_name']) . "', '" . tep_db_input($description['events_description']) . "', '" . tep_db_input($description['events_url']) . "', '0')");
					}
					
					tep_db_query("insert into " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " (events_id, events_categories_id) values ('" . (int)$dup_events_id . "', '" . (int)$events_categories_id . "')");
	    
						//copy the sessions details
					if (isset($HTTP_POST_VARS['copy_sessions'])){
						//copy recursive sessions
						$recursive_query=tep_db_query(	"SELECT recursive_sessions_id,events_id,sessions_start_date,sessions_end_date,sessions_type,sessions_type_option,sessions_type_daily_days,sessions_type_weekly_weeks,sessions_type_weekly_days," . 
													"sessions_type_monthly_days,sessions_type_monthly_months,sessions_type_monthly_weeks,sessions_type_monthly_weekdays,sessions_type_monthly_weekmonths,sessions_type_yearly_months," .
													"sessions_type_yearly_monthdays,sessions_type_yearly_weeks,sessions_type_yearly_weekdays,sessions_type_yearly_weekmonths " .
													" from " . TABLE_RECURSIVE_SESSIONS . " where events_id='" .(int)$events_id . "'");
						if (tep_db_num_rows($recursive_query)>0){
							while ($recursive_result=tep_db_fetch_array($recursive_query)){
								$old_id=$recursive_result["recursive_sessions_id"];
								unset($recursive_result["recursive_sessions_id"]);
								$recursive_result['events_id']=$dup_events_id;
								tep_db_perform(TABLE_RECURSIVE_SESSIONS,$recursive_result);
								$recursive_id=tep_db_insert_id();
			
								$session_query=tep_db_query("SELECT events_id,start_date,sessions_type,recursive_sessions_id from " . TABLE_EVENTS_SESSIONS . " where events_id='" . (int)$events_id . "' and recursive_sessions_id='" . (int)$old_id . "'");
								while($session_result=tep_db_fetch_array($session_query)){
									$session_result['events_id']=$dup_events_id;
									$session_result['recursive_sessions_id']=$recursive_id;
									tep_db_perform(TABLE_EVENTS_SESSIONS,$session_result);	
								}
							}
						} else {
							//copy single sessions
							$session_query=tep_db_query("SELECT events_id,start_date,sessions_type,recursive_sessions_id from " . TABLE_EVENTS_SESSIONS . " where events_id='" . (int)$events_id . "' and sessions_type='S'");
							while($session_result=tep_db_fetch_array($session_query)){
								$session_result['events_id']=$dup_events_id;
								tep_db_perform(TABLE_EVENTS_SESSIONS,$session_result);
							}
						}
						tep_set_event_limit_dates($dup_events_id);
					}
			}
			}

			tep_redirect(tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $events_categories_id . '&eID=' . $events_id));
			break;
		case 'new_event_preview':
		
				// copy image only if modified
			$events_image = new upload('events_image');
			$events_image->set_destination(DIR_FS_CATALOG_IMAGES);
			if ($events_image->parse() && $events_image->save()) {
				$events_image_name = $events_image->filename;
			} else {
				$events_image_name = (isset($HTTP_POST_VARS['events_previous_image']) ? $HTTP_POST_VARS['events_previous_image'] : '');
			}
			break;
		}
	}

// check if the catalog image directory exists
	if (is_dir(DIR_FS_CATALOG_IMAGES)) {
		if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
	} else {
		$messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
	}

	// WebMakers.com Added: Display Order
	switch (true) {
		case (EVENTS_CATEGORIES_SORT_ORDER=="events_name"):
			$order_it_by = "ed.events_name";
			break;
		case (EVENTS_CATEGORIES_SORT_ORDER=="events_name-desc"):
			$order_it_by = "ed.events_name DESC";
			break;
		default:
			$order_it_by = "ed.events_name";
			break;
	}
	$go_back_to=$REQUEST_URI;
?> 
<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/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script>
<?php
// WebMakers.com Added: Java Scripts
include(DIR_WS_INCLUDES . 'javascript/' . 'webmakers_added_js.php');
?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<div id="spiffycalendar" class="text"></div>
<script language="javascript" src="includes/http.js"></script>
<!-- header //-->
<?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">
	<?php   //----- new_category / edit_category (when ALLOW_CATEGORY_DESCRIPTIONS is 'true') -----
	if ($HTTP_GET_VARS['action'] == 'new_events_category_ACD' || $HTTP_GET_VARS['action'] == 'edit_events_category_ACD') {
		if ( ($HTTP_GET_VARS['ecID']) && (!$HTTP_POST_VARS) ) {
			$events_categories_query = tep_db_query("SELECT ec.events_categories_id, ecd.events_categories_name, ecd.events_categories_heading_title, ecd.events_categories_description, ec.events_categories_image, ec.parent_id, ec.sort_order, ec.date_added, ec.last_modified from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.events_categories_id = ecd.events_categories_id and ec.events_categories_id = '" . (int)$HTTP_GET_VARS['ecID'] . "' and ecd.language_id = '" . (int)$languages_id . "' order by ec.sort_order, ecd.events_categories_name");
			$events_category = tep_db_fetch_array($events_categories_query);
	
			$ecInfo = new objectInfo($events_category);
		} elseif ($HTTP_POST_VARS) {
			$ecInfo = new objectInfo($HTTP_POST_VARS);
			$events_categories_name = $HTTP_POST_VARS['events_categories_name'];
			$events_categories_heading_title = $HTTP_POST_VARS['events_categories_heading_title'];
			$events_categories_description = $HTTP_POST_VARS['events_categories_description'];
			$events_categories_url = $HTTP_POST_VARS['events_categories_url'];
		} else {
			$ecInfo = new objectInfo(array());
		}

		$languages = tep_get_languages();

		$text_new_or_edit = ($HTTP_GET_VARS['action']=='new_events_category_ACD') ? TEXT_INFO_HEADING_NEW_EVENTS_CATEGORY : TEXT_INFO_HEADING_EDIT_EVENTS_CATEGORY;
?>
	<tr>
		<td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
			<!--<tr>
				<td class="pageHeading"><?php //echo sprintf($text_new_or_edit, tep_output_generated_events_category_path($current_events_category_id)); ?></td>
				<td class="pageHeading" align="right"><?php //echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
			</tr>!-->
		</table>
		</td>
	</tr>
	<tr>
    	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
    </tr>
	<tr><?php echo tep_draw_form('new_events_category', FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $HTTP_GET_VARS['ecID'] . '&action=new_events_category_preview', 'post', 'enctype="multipart/form-data" onSubmit="javascript:return validate_image()"'); ?>
		<td>
		<table border="0" cellspacing="0" cellpadding="2">
		<?php
		for ($i=0; $i<sizeof($languages); $i++) {
		?>
			<tr>
				<td class="main"><?php if ($i == 0) echo TEXT_EDIT_EVENTS_CATEGORIES_NAME; ?></td>
				<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('events_categories_name[' . $languages[$i]['id'] . ']', (tep_not_null($events_categories_name[$languages[$i]['id']]) ? stripslashes($events_categories_name[$languages[$i]['id']]) : tep_get_events_category_name($ecInfo->events_categories_id, $languages[$i]['id']))); ?></td>
			</tr>
		<?php
		}
		?>
		<tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<?php
		for ($i=0; $i<sizeof($languages); $i++) {
		?>
		<tr>
			<td class="main"><?php if ($i == 0) echo TEXT_EDIT_EVENTS_CATEGORIES_HEADING_TITLE; ?></td>
			<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('events_categories_heading_title[' . $languages[$i]['id'] . ']', (tep_not_null($events_categories_heading_title[$languages[$i]['id']]) ? stripslashes($events_categories_heading_title[$languages[$i]['id']]) : tep_get_events_category_heading_title($ecInfo->events_categories_id, $languages[$i]['id']))); ?></td>
		</tr>
		<?php
		}
		?>
		<tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<?php
		for ($i=0; $i<sizeof($languages); $i++) {
		?>
		<tr>
			<td class="main" valign="top"><?php if ($i == 0) echo TEXT_EDIT_EVENTS_CATEGORIES_DESCRIPTION; ?></td>
			<td>
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
					<td class="main"><?php echo tep_draw_textarea_field('events_categories_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (tep_not_null($events_categories_description[$languages[$i]['id']]) ? stripslashes($events_categories_description[$languages[$i]['id']]) : tep_get_events_category_description($ecInfo->events_categories_id, $languages[$i]['id']))); ?></td>
				</tr>
			</table>
			</td>
		</tr>
		<?php
		}
		?>
		<tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr>
			<td class="main"><?php echo TEXT_EDIT_EVENTS_CATEGORIES_IMAGE; ?></td>
			<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('events_categories_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $ecInfo->events_categories_image . tep_draw_hidden_field('events_categories_previous_image', $ecInfo->events_categories_image); ?></td>
		</tr>
		<tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr>
			<td class="main"><?php echo TEXT_EDIT_EVENTS_CATEGORIES_SORT_ORDER; ?></td>
			<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sort_order', $ecInfo->sort_order, 'size="2"'); ?></td>
		</tr>
		<tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
	</table>
	</td>
	</tr>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	</tr>
	<tr>
		<td class="main" align="right"><?php echo tep_draw_hidden_field('events_categories_date_added', (($ecInfo->date_added) ? $ecInfo->date_added : getServerDate())) . tep_draw_hidden_field('parent_id', $ecInfo->parent_id) . tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . (isset($HTTP_GET_VARS['ecID'])?'&ecID=' . $HTTP_GET_VARS['ecID']:'')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
	</tr>
	<?php
	echo "</form>";
  //----- new_category_preview (active when ALLOW_CATEGORY_DESCRIPTIONS is 'true') -----
	} elseif ($HTTP_GET_VARS['action'] == 'new_events_category_preview') {
		if ($HTTP_POST_VARS) {
			$ecInfo = new objectInfo($HTTP_POST_VARS);
			$events_categories_name = $HTTP_POST_VARS['events_categories_name'];
			$events_categories_heading_title = $HTTP_POST_VARS['events_categories_heading_title'];
			$events_categories_description = $HTTP_POST_VARS['events_categories_description'];
			// copy image only if modified
			$events_categories_image = new upload('events_categories_image');
			$events_categories_image->set_destination(DIR_FS_CATALOG_IMAGES);
			if ($events_categories_image->parse() && $events_categories_image->save()) {
				$events_categories_image_name = $events_categories_image->filename;
			} else {
				$events_categories_image_name = $HTTP_POST_VARS['events_categories_previous_image'];
			}
			#     if ( ($events_categories_image != 'none') && ($events_categories_image != '') ) {
			#       $image_location = DIR_FS_CATALOG_IMAGES . $events_categories_image_name;
			#       if (file_exists($image_location)) @unlink($image_location);
			#       copy($events_categories_image, $image_location);
			#     } else {
			#       $events_categories_image_name = $HTTP_POST_VARS['events_categories_previous_image'];
			#     }
	    } else {
			$events_category_query = tep_db_query("SELECT ec.events_categories_id, ecd.language_id, ecd.events_categories_name, ecd.events_categories_heading_title, ecd.events_categories_description, ec.events_categories_image, ec.sort_order, ec.date_added, ec.last_modified from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.events_categories_id = ecd.events_categories_id and ec.events_categories_id = '" . (int)$HTTP_GET_VARS['ecID'] . "' and ecd.language_id='" . (int)$languages_id . "'");
			$events_category = tep_db_fetch_array($events_category_query);
			
			$ecInfo = new objectInfo($events_category);
			$events_categories_image_name = $ecInfo->events_categories_image;
		}

		$form_action = ($HTTP_GET_VARS['ecID']) ? 'update_events_category' : 'insert_events_category';
		
		echo tep_draw_form($form_action, FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $HTTP_GET_VARS['ecID'] . '&action=' . $form_action, 'post', 'enctype="multipart/form-data"');
		
		$languages = tep_get_languages();
		for ($i=0; $i<sizeof($languages); $i++) {
			if ($HTTP_GET_VARS['read'] == 'only') {
				$ecInfo->events_categories_name = tep_get_events_category_name($ecInfo->events_categories_id, $languages[$i]['id']);
				$ecInfo->events_categories_heading_title = tep_get_events_category_heading_title($ecInfo->events_categories_id, $languages[$i]['id']);
				$ecInfo->events_categories_description = tep_get_events_category_description($ecInfo->events_categories_id, $languages[$i]['id']);
			} else {
				$ecInfo->events_categories_name = tep_db_prepare_input($events_categories_name[$languages[$i]['id']]);
				$ecInfo->events_categories_heading_title = tep_db_prepare_input($events_categories_heading_title[$languages[$i]['id']]);
				$ecInfo->events_categories_description = tep_db_prepare_input($events_categories_description[$languages[$i]['id']]);
			}
	  
	?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . $ecInfo->events_categories_heading_title; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo tep_image(DIR_WS_CATALOG_IMAGES . $events_categories_image_name, $ecInfo->events_categories_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $ecInfo->events_categories_description; ?></td>
      </tr>

<?php
    }
    if ($HTTP_GET_VARS['read'] == 'only') {
      if ($HTTP_GET_VARS['origin']) {
        $pos_params = strpos($HTTP_GET_VARS['origin'], '?', 0);
        if ($pos_params != false) {
          $back_url = substr($HTTP_GET_VARS['origin'], 0, $pos_params);
          $back_url_params = substr($HTTP_GET_VARS['origin'], $pos_params + 1);
        } else {
          $back_url = $HTTP_GET_VARS['origin'];
          $back_url_params = '';
        }
      } else {
        $back_url = FILENAME_EVENTS_CATEGORIES;
        $back_url_params = 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id;
      }
?>
      <tr>
        <td align="right"><?php echo '<a href="' . tep_href_link($back_url, $back_url_params, 'NONSSL') . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
      </tr>
<?php
    } else {
?>
      <tr>
        <td align="right" class="smallText">
<?php
/* Re-Post all POST'ed variables */
      reset($HTTP_POST_VARS);
      while (list($key, $value) = each($HTTP_POST_VARS)) {
        if (!is_array($HTTP_POST_VARS[$key])) {
          echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
        }
      }
      $languages = tep_get_languages();
      for ($i=0; $i<sizeof($languages); $i++) {
        echo tep_draw_hidden_field('events_categories_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($events_categories_name[$languages[$i]['id']])));
        echo tep_draw_hidden_field('events_categories_heading_title[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($events_categories_heading_title[$languages[$i]['id']])));
        echo tep_draw_hidden_field('events_categories_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($events_categories_description[$languages[$i]['id']])));
      }
      echo tep_draw_hidden_field('X_events_ategories_image', stripslashes($events_categories_image_name));
      echo tep_draw_hidden_field('events_categories_image', stripslashes($events_categories_image_name));

      echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';

      if ($HTTP_GET_VARS['ecID']) {
        echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
      } else {
        echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
      }
      echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_MAINPAGE, 'top=1&mPath=2') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
?></td>
      </form></tr>
<?php
    }
  } elseif ($action == 'new_event') {
		$parameters = array('events_name' => '',
				'events_description' => '',
				'events_url' => '',
				'events_id' => '',
				'events_image' => '',
				'events_fees' => '',
				'events_date_added' => '',
				'events_last_modified' => '',
				'events_location'=>'',
				'events_date_available' => '',
				'events_max_reserve' => '1',
				'events_overbook_reserve'=>0,
				'subscription_overbook_reserve'=>0,
				'events_start_time'=>'00:00:AM',
				'events_end_time='>'00:00:AM',
				'events_instrutor'=>'',
				'events_backup_instructor'=>'',
				'events_payment'=>'',
				'refund_percentage1'=>'',
				'refund_percentage2'=>'',
				'refund_percentage3'=>'',
				'events_wait_list'=>'Y',
				'priority_vip'=>'1',
				'priority_firstcome'=>'2',
				'priority_custom'=>'3',
				'priority_question'=>'',
				'waitsize_vip'=>'1',
				'waitsize_firstcome'=>'1',
				'waitsize_custom'=>'1',
				'events_conditions'=>'',
				'waitfee_vip'=>'0',
				'waitfee_firstcome'=>'0',
				'waitfee_custom'=>'0',
				'events_forward_period'=>'',
				'events_forward_length'=>'',
				'events_pending_period'=>'',
				'events_renewal_start'=>'FLS',
				'events_renewal_end'=>'',
				'session_gaps'=>"N",
				'session_reduction'=>"N",
				'session_style'=>'S',
				'instructors_rate_type'=>'GP',
				'instructors_rate'=>0,
				'instructors_base_rate'=>0,
				'events_status' => '1',
				'events_group_bookings'=>'Y',
				'events_group_min'=>'0',
				'events_group_max'=>'0',
				'link_service' =>'L',
				'service_id' =>''
				);

    $eInfo = new objectInfo($parameters);
    require(DIR_WS_CLASSES . 'payment.php');
    $payment_modules = new payment;

    if (isset($HTTP_GET_VARS['eID']) && empty($HTTP_POST_VARS)) {
	  // This is for Diveabout
      $event_query = tep_db_query("SELECT ed.events_name, ed.events_description, ed.events_url, e.events_id, e.events_image, e.events_location," .
                                   "e.events_date_added, e.events_last_modified, date_format(e.events_date_available, '%Y-%m-%d') " .
								   "as events_date_available, e.events_status,  e.events_tax_class_id,e.refund_percentage1,e.refund_percentage2,e.refund_percentage3," .
								   "e.events_max_reserve,e.events_overbook_reserve,e.subscription_overbook_reserve,time_format(e.events_start_time,'%h:%i:%p') as events_start_time,time_format(e.events_end_time,'%h:%i:%p') as events_end_time,e.events_instructor,e.events_backup_instructor ,e.events_fees,e.events_tax_class_id,e.events_payment," .
								   "e.events_wait_list,e.priority_vip,e.priority_firstcome,e.priority_custom,e.priority_question,e.waitsize_vip,e.waitsize_firstcome,e.waitsize_custom,e.events_conditions,e.waitfee_vip,e.waitfee_firstcome,e.waitfee_custom,e.events_forward_period,e.events_forward_length,e.events_pending_period,e.events_renewal_start,e.events_renewal_end,e.session_gaps,e.session_reduction,e.session_style,e.instructors_rate_type,e.instructors_rate, " .
								   "e.instructors_base_rate,e.events_group_bookings,e.events_group_min,e.events_group_max,e.link_service,service_id from " . 
								   TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed where e.events_id=ed.events_id " .
								   " and e.events_id = '" . (int)$HTTP_GET_VARS['eID'] . "' and ed.language_id = '" . (int)$languages_id . "'");
      $event = tep_db_fetch_array($event_query);

      $eInfo->objectInfo($event);
    } elseif (tep_not_null($HTTP_POST_VARS)) {
      $eInfo->objectInfo($HTTP_POST_VARS);
      $events_name = $HTTP_POST_VARS['events_name'];
      $events_description = $HTTP_POST_VARS['events_description'];
      $events_url = $HTTP_POST_VARS['events_url'];
    }
    $events_percent_array=array();
    for($icnt=5;$icnt<=100;$icnt+=5)
      $events_percent_array[]=array('id'=>$icnt,'text'=>$icnt);
    
    #get tax descriptions to display in tax selection
    $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
    $tax_class_query = tep_db_query("SELECT tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
    while ($tax_class = tep_db_fetch_array($tax_class_query)) {
      $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
                                 'text' => $tax_class['tax_class_title']);
    }   
    
    #get instructor descriptions to display in instructor selection
    $instructor_array=array();
    $instructor_query=tep_db_query("SELECT a.admin_id,a.admin_firstname,a.admin_lastname from " . TABLE_ADMIN . " a, " . TABLE_ADMIN_GROUPS . " ag where a.admin_groups_id=ag.admin_groups_id and ag.admin_groups_name='" . TEXT_INSTRUCTOR_ENTRY . "' order by a.admin_firstname,a.admin_lastname");
    while ($instructorfetch = tep_db_fetch_array($instructor_query)) {
      $instructor_array[] = array('id' => $instructorfetch['admin_id'],
                                    'text' => $instructorfetch['admin_firstname'] . '&nbsp;' . $instructorfetch['admin_lastname']);
    }	
	$services_array=array();
    $services_array = array(array('id' => '-1', 'text' => TEXT_SELECT));
	$services_query=tep_db_query("select op.products_id,op.products_name from ".TABLE_SERVICES ." s, ".TABLE_ORDERS ." o, ".TABLE_ORDERS_PRODUCTS ." op, ".TABLE_SERVICES_DESCRIPTION ." sd where s.service_id=sd.service_id and o.orders_id=op.orders_id and op.products_type='V' and lcase(o.payment_method)='internal only' and op.products_id=s.service_id");
	while($services_result=tep_db_fetch_array($services_query)){
		$services_array[]=array('id' => $services_result['products_id'],
								'text' => $services_result['products_name']);
	}

    # get selected categories
    $events_categories_query_selected = tep_db_query("SELECT events_categories_id from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$HTTP_GET_VARS['eID'] . "'");
    $events_categories_array_selected = array(array('id' => ''));
    while ($events_categories = tep_db_fetch_array($events_categories_query_selected)) {
      $events_categories_array_selected[] = array('id' => $events_categories['events_categories_id']);
    }
	
	$eventsubs=tep_db_query("select * from ".TABLE_EVENTS_TO_SUBSCRIPTIONS ." where events_id='" .(int)$HTTP_GET_VARS['eID'] ."'");
	while($eventsubsres=tep_db_fetch_array($eventsubs)) {
	$subscription_categories_array_selected[]=array('id' => $eventsubsres['subscription_id']);
	}
    $events_categories_array = array(array('id' => '', 'text' => TEXT_NONE));
	
    #PR Algozone: Categories list displays only for one languge (Deafault is English)
    $language_id = 1;
    $events_categories_array = tep_get_events_category_tree(); 

    $priority_array=array();
    $priority_array[]=array('id'=>'1','text'=>'1');
    $priority_array[]=array('id'=>'2','text'=>'2');
    $priority_array[]=array('id'=>'3','text'=>'3');
    
    $questions_array=array(array('id'=>0,'text'=>'None'));
    $questions_query=tep_db_query("SELECT question_id,question_title from " . TABLE_POP_QUESTIONS);

    while($questions=tep_db_fetch_array($questions_query))
       $questions_array[]=array('id'=>$questions['question_id'],'text'=>$questions['question_title']);

    $form_action = ($HTTP_GET_VARS['eID']) ? 'update_event' : 'insert_event';

    $languages = tep_get_languages();


	$status_array=array(array('id'=>1,'text'=>TEXT_HIDE_NONE),
						array('id'=>0,'text'=>TEXT_HIDE_ALWAYS),
						array('id'=>2,'text'=>TEXT_HIDE_START),
						array('id'=>3,'text'=>TEXT_HIDE_END));
						
    if (!isset($eInfo->events_status)) $eInfo->events_status = '0';
    
    $selection=$payment_modules->selection();
    $events_payment_array=array(array('id'=>'none','text'=> TEXT_NONE));
    for($icnt=0;$icnt<sizeof($selection);$icnt++){
      $events_payment_array[]=array('id'=>$selection[$icnt]['id'],'text'=>$selection[$icnt]['module']);}

       $current_date=getServerDate();

    $hour_array=array();
    for($icnt=1;$icnt<=12;$icnt++){
      if ($icnt<10) $hour_array[]=array('id'=>$icnt,'text'=>'0' . $icnt);
      else $hour_array[]=array('id'=>$icnt,'text'=>$icnt);
    }
    $minute_array=array();
    for($icnt=0;$icnt<=59;$icnt=$icnt+5){
      if ($icnt<10) $minute_array[]=array('id'=>$icnt,'text'=>'0' . $icnt);
      else $minute_array[]=array('id'=>$icnt,'text'=>$icnt);
    }
    $day_session_array[]=array('id'=>'AM','text'=>'AM');
    $day_session_array[]=array('id'=>'PM','text'=>'PM');
    
    $location_query=tep_db_query("SELECT * from " . TABLE_EVENTS_LOCATIONS . ' order by location_name');
    $location_array=array();
    while($location_result=tep_db_fetch_array($location_query)){
       $location_array[]=array('id'=>$location_result['location_id'],'text'=>$location_result['location_name'],'seats'=>$location_result["location_seats"]);
    }
	
    $service_location_query=tep_db_query("SELECT sl.*,s.service_id from " . TABLE_SERVICES." s, ". TABLE_SERVICES_LOCATIONS . ' sl where s.service_location=sl.service_location_id order by service_location_name');
    $service_location_array=array();
    while($service_location_result=tep_db_fetch_array($service_location_query)){
       $service_location_array[]=array('id'=>$service_location_result['service_id'],'seats'=>$service_location_result["service_location_seats"]);
    }

	$rate_type_array=array(	array('id'=>'GP','text'=>TEXT_RATE_TYPE_GP),
							array('id'=>'MU','text'=>TEXT_RATE_TYPE_MU),
							array('id'=>'FL','text'=>TEXT_RATE_TYPE_FL));
							
    $renewal_array=array(array('id'=>'FLS','text'=>TEXT_FLS),
                                   array('id'=>'SLS','text'=>TEXT_SLS),
                                   array('id'=>'DLS','text'=>TEXT_DLS),
								   array('id'=>'OBS','text'=>TEXT_OBS),
								   array('id'=>'TBS','text'=>TEXT_TBS));
    /*$message_query=tep_db_query("SELECT message_send from " . TABLE_EVENTS_MESSAGES . " where events_id='" . (int)$HTTP_GET_VARS['eID'] . "' and message_type='RNR'");
    if ($message_result=tep_db_fetch_array($message_query))
        $renewal_period_start=$message_result['message_send'];*/
?>
<script language="javascript"> 
var locations=Array();
var tax_rates = new Array();
var lang=new Array();
var sel_object="";
var service_locations = new Array();
<?php
    for ($i=0, $n=sizeof($location_array); $i<$n; $i++) {
		if ($location_array[$i]['id'] > 0) {
	        echo 'locations["' . $location_array[$i]['id'] . '"] = ' . $location_array[$i]['seats'] . ';' . "\n";
		}
    }
    for ($i=0, $n=sizeof($service_location_array); $i<$n; $i++) {
		if ($service_location_array[$i]['id'] > 0) {
	        echo 'service_locations["' . $service_location_array[$i]['id'] . '"] = ' . $service_location_array[$i]['seats'] . ';' . "\n";
		}
    }
?>

<?php
    for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) {
      if ($tax_class_array[$i]['id'] > 0) {
        echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate_value($tax_class_array[$i]['id']) . ';' . "\n";
      }
    }
    $j=0;
			for ($l=0; $l<sizeof($languages); $l++) { ?>
			lang[<?php echo $j;?>]="<?php echo $languages[$l]['id'];?>";	
		<?php $j++; 	
			}	
		?>	
 function change_waitfee(txtBox){
   if (txtBox.name!="waitfee_vip")
      document.new_event.waitfee_vip.value=txtBox.value;
   if (txtBox.name!="waitfee_firstcome")
      document.new_event.waitfee_firstcome.value=txtBox.value;
   if (txtBox.name!="waitfee_custom")
      document.new_event.waitfee_custom.value=txtBox.value;
 }
 function ValidateForm(){
     var error_result;
     var count=0;
     error_result="";
     count=0; 
	var image_types=Array(".png",".jpg",".jpeg",".gif");
	if (document.new_event.elements["events_image"].value!="" && !check_mime_type(document.new_event.elements["events_image"],image_types)){
		error_result+="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
	}
	if (document.new_event.elements["events_name["+lang[0]+"]"]){
	  for (icnt=0;icnt<lang.length;icnt++){ 
	    if (document.new_event.elements["events_name["+lang[icnt]+"]"].value==""){
	      error_result+="<?php echo tep_db_input(TEXT_ERR_EMPTY_EVENT_NAME); ?>\n";break;
	    }
	  } 
	} else {
	  if (document.new_event.events_name.value=="")  error_result+="<?php echo tep_db_input(TEXT_ERR_EMPTY_EVENT_NAME); ?>\n";
	}
     
      if (document.new_event.events_categories_ids.selectedIndex<0){
        		error_result+="<?php echo tep_db_input(TEXT_ERR_SELECT_CATEGORY); ?>\n";
      } else if (document.new_event.events_wait_list.checked==true){
           if (document.new_event.waitsize_vip.value=="" || document.new_event.waitsize_firstcome.value=="" || document.new_event.waitsize_custom.value==""){
	     			error_result+="<?php echo tep_db_input(TEXT_ERR_EMPTY_WAITSIZE); ?>\n";
			  } else if(isNaN(parseInt(document.new_event.waitsize_vip.value))==true || isNaN(parseInt(document.new_event.waitsize_firstcome.value))==true || isNaN(parseInt(document.new_event.waitsize_custom.value))==true){
			     error_result+="<?php echo tep_db_input(TEXT_ERR_INVALID_WAITSIZE); ?>\n";
			  } else if(document.new_event.waitfee_vip.value==""){
			    error_result+="<?php echo tep_db_input(TEXT_ERR_EMPTY_WAITFEE); ?>\n";
			  } else if (isNaN(parseInt(document.new_event.waitfee_vip.value))==true){
			     error_result+="<?php echo tep_db_input(TEXT_ERR_INVALID_WAITFEE); ?>\n";
			  }
      }
    
     if (document.new_event.events_forward_period.checked==true){
      if (document.new_event.events_forward_length.value==""){
	     error_result+="<?php echo tep_db_input(TEXT_ERR_EMPTY_FORWARD_PERIOD); ?>\n";
	   } else if(isNaN(parseInt(document.new_event.events_forward_length.value))==true){
	     error_result+="<?php echo tep_db_input(TEXT_ERR_INVALID_FORWARD_PERIOD); ?>\n";
	   }
     }  
	  for(i=0;i<document.new_event.link_service.length;i++){
		  if(document.new_event.link_service[i].checked){
			if(document.new_event.link_service[i].value=='L'){
				  if (parseInt(document.new_event.events_max_reserve.value)>getLocationSeats()){ 
					 error_result+="<?php echo tep_db_input(TEXT_ERR_MAX_RESERVATIONS_GREATER); ?>\n";
				  }
			 } else if(document.new_event.link_service[i].value=='S'){
			 		if(document.new_event.sel_customers.options[document.new_event.sel_customers.selectedIndex].value=='nil'){
						error_result+="<?php echo tep_db_input(TEXT_ERR_NO_BOOKINGS_EXIST);?>\n";
					} else { 
						if(document.new_event.sel_services.selectedIndex<=0){
							error_result+="<?php echo tep_db_input(TEXT_ERR_SELECT_SERVICE);?>\n";
						} else{
							var selectedindex=document.new_event.sel_services.selectedIndex;
							  if (parseInt(document.new_event.events_max_reserve.value)>getServiceLocationSeats()){ 
								// error_result+="<?php //echo tep_db_input(TEXT_ERR_MAX_SERVICE_RESERVATIONS_GREATER); ?>\n";
								error_result+="Only "+ getServiceLocationSeats() + " seats are available in selected service. \n";
								} 
						}	
					}
				}
				break;
			}	
	  }	
	   if (document.new_event.events_group_bookings.checked) {
			if (!isNumeric(parseInt(document.new_event.events_group_min.value),1) ||document.new_event.events_group_min.value<=0){
				error_result+="<?php echo tep_db_input(TEXT_ERR_GROUP_MIN_VALUE); ?>\n";
			} else if (!isNumeric(parseInt(document.new_event.events_group_max.value),1)){
				error_result+="<?php echo tep_db_input(TEXT_ERR_GROUP_MAX_VALUE); ?>\n";
			} else if (parseInt(document.new_event.events_group_min.value)>parseInt(document.new_event.events_group_max.value)){
				error_result+="<?php echo tep_db_input(TEXT_ERR_GROUP_MIN_VALUE_GREATER); ?>\n";
			} 
			if(parseInt(document.new_event.events_group_max.value) >= parseInt(document.new_event.events_max_reserve.value))
				error_result+="<?php echo tep_db_input(TEXT_ERR_MAX_RESERVE_GREATER);?>\n" ;
		 }
    if (error_result!=""){
       alert(error_result);
       return false;
     }
     return true;
}
	function isNumeric(value,minimumValue,maximumValue){
		value=parseFloat(value);
		if (isNaN(value)) return false;
		if (value<minimumValue) return false;
	
		if (maximumValue>0 && value>maximumValue) return false;
			return true;
		}
	function doRound(x, places) {
	  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
	}
	
	function getTaxRate() {
	  var selected_value = document.forms["new_event"].events_tax_class_id.selectedIndex;
	  var parameterVal = document.forms["new_event"].events_tax_class_id[selected_value].value;
	
	  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
		return tax_rates[parameterVal];
	  } else {
		return 0;
	  }
	  }
 function getLocationSeats(){
	  var selected_value = document.forms["new_event"].events_location.selectedIndex;
	  var parameterVal = document.forms["new_event"].events_location[selected_value].value;
	  if ( (parameterVal > 0) && (locations[parameterVal] > 0) ) {
		return locations[parameterVal];
	  } else {
		return 0;
	  }
  }
 function getServiceLocationSeats(){
	  var selected_value = document.forms["new_event"].sel_services.selectedIndex;
	  var parameterVal = document.forms["new_event"].sel_services[selected_value].value;

	  if ( (parameterVal > 0) && (service_locations[parameterVal] > 0) ) {
		return service_locations[parameterVal];
	  } else {
		return 0;
	  }
  }


	function updateGross() {
	  var taxRate = getTaxRate();
	  var grossValue = document.forms["new_event"].events_fees_net.value;
	
	  if (taxRate > 0) {
		grossValue = grossValue * ((taxRate / 100) + 1);
	  }
	
	  document.forms["new_event"].events_fees_gross.value = doRound(grossValue, 4);
	}
	
	function updateNet() {
	  var taxRate = getTaxRate();
	  var netValue = document.forms["new_event"].events_fees_gross.value;
	
	  if (taxRate > 0) {
		netValue = netValue / ((taxRate / 100) + 1);
	  }
	
	  document.forms["new_event"].events_fees_net.value = doRound(netValue, 4);
	}

	function do_change(obj){
		var command='';
		if(obj.value=='L'){
			document.getElementById('locations').style.display="";
			document.getElementById('customers').style.display="none";
			document.getElementById('services').style.display="none";
		} else if(obj.value=='S'){
			var service_count=customers_count="";
			document.getElementById('locations').style.display="none";
			document.getElementById('customers').style.display="";
			for(i=document.new_event.sel_services.options.length;i>=0;i--) {
					document.new_event.sel_services.options[i]=null;
				}
			var Option_value=new Option('<?php echo TEXT_SELECT;?>','-1');
			document.new_event.sel_services.options[0] = Option_value;
			command="<?php echo tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $HTTP_GET_VARS['eID'] . '&action='. $form_action.'&command=fetch_customer_details');?>";
			do_get_command(command);
		}
		
	}
	function init(){
			document.getElementById('locations').style.display="none";
			document.getElementById('customers').style.display="";
			document.getElementById('services').style.display="";
			command="<?php echo tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $HTTP_GET_VARS['eID'] . '&action='. $form_action.'&command=fetch_customer_details');?>";
			do_get_command(command);
	}
	
	
	/*function sel_service(){
		var frm;
		frm=document.new_event;
		if(frm.sel_services.selectedIndex>0){
			var selectedindex=document.new_event.sel_services.selectedIndex;
			  if (parseInt(document.new_event.events_max_reserve.value)>getServiceLocationSeats()){ 
				 alert("<?php //echo tep_db_input(TEXT_ERR_MAX_RESERVATIONS_GREATER); ?>");
				} 
		}		
	}*/

	function do_submit(customer_id) {
			command="<?php echo tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $HTTP_GET_VARS['eID'] . '&action='. $form_action.'&command=fetch_service_details');?>&customers_id="+customer_id;
			do_get_command(command);
	}
	function do_result(result){
		var customers=new Array();
		if(result.indexOf('#*#')>=0){
			var result=result.substring(0,result.length-3);
			 if(result.indexOf('#')>=0 && result.length>0)
				{
				temp=result.split('#');
				for(i=0;i<temp.length-1;i++)
				{
					content=temp[i];
					temp2=content.split(':');
					customers[i]=new Array(2);
					customers[i][0]=temp2[0];
					customers[i][1]=temp2[1];
				}
				document.getElementById('services').style.display="";
				fill_customers(customers);
			} else{
					var Option_value=new Option('<?php echo TEXT_NO_CUSTOMERS_AVAILABLE;?>','nil');
					document.new_event.sel_customers.options[0] = Option_value;
					alert('<?php echo TEXT_ERR_NO_BOOKINGS_EXIST;?>');
			}
		} else if(result.indexOf('^*^')>=0){
		var result=result.substring(0,result.length-3);
		if(result.indexOf('^')>=0)
		{
			temp=result.split('^');
			for(i=0;i<temp.length-1;i++)
			{
				content=temp[i];
				temp2=content.split(':');
				customers[i]=new Array(2);
				customers[i][0]=temp2[0];
				customers[i][1]=temp2[1];
			}
			fill_services(customers);
			}
		}		
	}
	 function fill_customers(customers){
			with (document.new_event) {	
				for(i=sel_customers.options.length;i>=0;i--) {
					sel_customers.options[i]=null;
				}
				var Option_value=new Option('<?php echo TEXT_SELECT;?>','-1');
				document.new_event.sel_customers.options[0] = Option_value;
				for(i=0; i < customers.length; i++){
						var Option_value=new Option(customers[i][1],customers[i][0]);
						sel_customers.options[sel_customers.options.length] = Option_value;
				}
				if (customers.length>1 && sel_customers.selectedIndex<0) sel_customers.selectedIndex=0;
			}
				
	}
	 function fill_services(customers){
			with (document.new_event) {	
				for(i=sel_services.options.length;i>=0;i--) {
					sel_services.options[i]=null;
				}
				var Option_value=new Option('<?php echo TEXT_SELECT;?>','-1');
				document.new_event.sel_services.options[0] = Option_value;
				for(i=0; i < customers.length; i++){
						var Option_value=new Option(customers[i][1],customers[i][0]);
						sel_services.options[sel_services.options.length] = Option_value;
				}
				if (customers.length>1 && sel_services.selectedIndex<0) sel_services.selectedIndex=0;
			}
				
	} 
</script>
    <?php echo tep_draw_form('new_event', FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $HTTP_GET_VARS['eID'] . '&action='. $form_action, 'post', 'onSubmit="return ValidateForm();" enctype="multipart/form-data"'); ?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo sprintf(TEXT_NEW_EVENT, tep_output_generated_events_category_path($current_events_category_id)); ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
	  
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
	  
		<tr>
			<td>
			<table border="0" cellspacing="0" cellpadding="2">
				<tr>
					<td>
					<table border=0 cellpadding="0" cellspacing="0">
						 <!--<tr>
				           <td class="main" colspan="5"><textarea rows="24" cols="80" name="events_des" id="events_des">/td>
				         </tr>-->
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_EVENTS_STATUS; ?></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_pull_down_menu('events_status', $status_array, $eInfo->events_status); ?></td>
							<?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
							<td class="main" width="150" valign="top"><?php echo TEXT_EVENTS_DATE_AVAILABLE; ?><br><small>(<?php echo $date_format;?>)</small></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_input_field("events_date_available",(tep_not_null($eInfo->events_date_available)?format_date($eInfo->events_date_available):format_date($current_date)),"size=10",false,'text',false);?>
							<a href="javascript:show_calendar('new_event.events_date_available',null,null,'<?php echo $date_format;?>');"
							onmouseover="window.status='Date Picker';return true;"
							onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
							</a>
							
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td>
					<table border=0 cellpadding="0" cellspacing="0">
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_EVENTS_CATEGORIES; ?></td>
							<td class="main" width="200"><?php echo tep_draw_mselect_menu('events_categories_ids[]', $events_categories_array, $events_categories_array_selected, 'size=10 id=events_categories_ids style="width:400"'); ?></td>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<?php tep_content_title_top("General"); ?>
				<tr>
					<td>
					<table border="0" cellpadding="4" cellspacing="0">
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
										<tr height="30">
											<td class="main" width="150"><?php if ($i == 0) echo TEXT_EVENTS_NAME; ?></td>
											<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']);?></td>
											<td class="main"><?php echo tep_draw_input_field('events_name[' . $languages[$i]['id'] . ']', (isset($events_name[$languages[$i]['id']]) ? $events_name[$languages[$i]['id']] : tep_get_events_name($eInfo->events_id, $languages[$i]['id'])),' size=40');?></td>
										</tr>
								<?php
								}
								?>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr>
										<td class="main" valign="top" width="150"><?php if ($i == 0) echo TEXT_EVENTS_DESCRIPTION; ?></td>
										<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
										<td>
										<table border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td class="main"><?php echo tep_draw_textarea_field('events_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24', (isset($events_description[$languages[$i]['id']]) ? $events_description[$languages[$i]['id']] : tep_get_events_description($eInfo->events_id, $languages[$i]['id'])),'id="events_description[' . $languages[$i]['id'] . ']"'); ?></td>
											</tr>
										</table>
										</td>
									</tr>
									<tr height="10"></tr>
								<?php
								}
								?>
							</table>
							</td>
						</tr>
						
						<tr>
							<td  width="100%">
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr height="30">
										<td class="main" width="100">
										<table border="0" cellpadding="0" cellspacing="0">
											<tr>
												<td class="main" width="100" nowrap="nowrap"><?php if ($i == 0) echo TEXT_EVENTS_URL . tep_draw_separator('pixel_trans.gif', '2', '10') . '<br><small>' . TEXT_EVENTS_URL_WITHOUT_HTTP . '</small>' . tep_draw_separator('pixel_trans.gif', '10', '10'); ?></td>
												<td class="main" align="right"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']);?></td>
												<td class="main" align="right">&nbsp;&nbsp;&nbsp;<?php echo tep_draw_input_field('events_url[' . $languages[$i]['id'] . ']', (isset($events_url[$languages[$i]['id']]) ? $events_url[$languages[$i]['id']] : tep_get_events_url($eInfo->events_id, $languages[$i]['id'])),'size=40');?></td>
											</tr>
										</table>
										</td>
										
										<?php if($i==0){?>
										<td class="main" colspan="2" nowrap="nowrap" valign="middle"><?php echo "&nbsp;&nbsp;" . TEXT_EVENTS_IMAGE . "&nbsp;&nbsp;" . tep_draw_file_field('events_image') . '&nbsp;&nbsp;' . $eInfo->events_image . tep_draw_hidden_field('events_previous_image', $eInfo->events_image); ?></td>
										<?php }else{echo "<td class='main' colspan='2'>&nbsp;</td>";}?>
									</tr>
								<?php
								}
								?>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>		  
								<tr>
									<?php $time_split=explode(":",$eInfo->events_start_time); 
									if ($time_split[2]=='PM' && $time_split[0]>12) $time_split[0]=$time_split[0]-12;?>
									
										<td class="main" width="300">
													<?php echo TEXT_EVENTS_START_TIME . '&nbsp;'; 
													 echo tep_draw_pull_down_menu('start_time_hours',$hour_array,$time_split[0]) . ' : ' . tep_draw_pull_down_menu('start_time_minutes',$minute_array,$time_split[1]) . ' ' . tep_draw_pull_down_menu('start_time_session',$day_session_array,$time_split[2]); ?></td>
													<?php $time_split=explode(":",$eInfo->events_end_time); 
															if ($time_split[2]=='PM' && $time_split[0]>12) $time_split[0]=$time_split[0]-12;?>
											
										<td class="main"  align="left" nowrap="nowrap">
										<?php echo tep_draw_radio_field('link_service','L',($eInfo->link_service=='L')?true:false,'','onClick="javascript:do_change(this);"').'&nbsp;'.TEXT_CHOOSE_LOCATIONS.'&nbsp;'.tep_draw_radio_field('link_service','S',($eInfo->link_service=='S')?true:false,'','onClick="javascript:do_change(this);"').'&nbsp;'.TEXT_LINK_SERVICES;?></td>
								</tr>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" width="350" nowrap="nowrap"><?php //echo tep_draw_separator('pixel_trans.gif','90','10')?><?php echo TEXT_EVENTS_END_TIME . "&nbsp;&nbsp;"; ?>
									<?php echo tep_draw_pull_down_menu('end_time_hours',$hour_array,$time_split[0]) . ' : ' . tep_draw_pull_down_menu('end_time_minutes',$minute_array,$time_split[1]) . '  ' . tep_draw_pull_down_menu('end_time_session',$day_session_array,$time_split[2]); ?></td>
									<td class="main"  align="left">
										<table border="0"  cellpadding="0" cellspacing="0">
											<tr>
												<td class="main" id="locations" align="left"><?php 
												echo '&nbsp;'.TEXT_EVENTS_LOCATION;
												echo tep_draw_separator('pixel_trans.gif', '15', '10') . tep_draw_pull_down_menu('events_location', $location_array,$eInfo->events_location);?>
												</td>
												<td  id="customers" style="display:none" class="main"><?php
												echo TEXT_CHOOSE_CUSTOMER;
												echo tep_draw_pull_down_menu('sel_customers',array(),$service_customer_selected,'onChange=javascript:do_submit(this.value);');
												?>
												</td>
											</tr>
										</table>
								</tr>	
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>		
								<tr id="services" style="display:none">
									<td class="main" width="350"><?php echo TEXT_CHOOSE_SERVICE;?>
									<?php echo tep_draw_separator('pixel_trans.gif', '1', '10') . tep_draw_pull_down_menu('sel_services',$services_array,$eInfo->service_id);?></td>
								</tr>	
								<tr>
									<td class="main" nowrap="nowrap"><?php echo TEXT_EVENTS_MAX_RESERVE; ?>
									<?php 
										echo tep_draw_input_field('events_max_reserve',(tep_not_null($eInfo->events_max_reserve) ? $eInfo->events_max_reserve:''),'size=10 maxlength=6');
										echo tep_draw_hidden_field('old_max_reserve',$eInfo->events_max_reserve);
									?>
									</td>
									<td class="main" nowrap="nowrap" align="left"><?php echo  TEXT_EVENTS_OVERBOOK_RESERVE . "&nbsp;"; ?>
									<?php 
										echo tep_draw_input_field('events_overbook_reserve',(tep_not_null($eInfo->events_overbook_reserve) ? $eInfo->events_overbook_reserve:0),'size=10 maxlength=6');
									?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
					</table>
					</td>
				</tr>
				<?php tep_content_title_bottom(); ?>
				<?php tep_content_title_top("Costs"); ?>
					<tr>
						<td>
						<table border="0"  cellpadding="4" cellspacing="0" width="100%">
							
							<tr>
								<td class="main"><?php 
								 	  $price=$eInfo->events_fees;
			           				  if(strpos($price,".") && substr($price,strpos($price,"."))<=0) $price=(int)$price;
								 	  echo TEXT_EVENTS_TAX_CLASS .tep_draw_separator('pixel_trans.gif',10,10) . tep_draw_pull_down_menu('events_tax_class_id', $tax_class_array, $eInfo->events_tax_class_id, 'onchange="updateGross()"');
									  echo tep_draw_separator('pixel_trans.gif',30,10).TEXT_EVENTS_FEES_NET_INFO . tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('events_fees_net', $price, 'onKeyUp="updateGross()"'); 
									  echo tep_draw_separator('pixel_trans.gif',30,10).TEXT_EVENTS_FEES_GROSS_INFO .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('events_fees_gross', $eInfo->events_fees, 'OnKeyUp="updateNet()"');
								?>
								</td>
							</tr>
							<tr>
								
								<td class="main"><?php echo TEXT_EVENTS_REFUND_PAYMENT; 
								 $events_refund_pay = $events_payment_array;
									  $events_refund_length = count($events_refund_pay);
								      for($k=0;$k<$events_refund_length;$k++)
										  $events_refund_pay[$k]['text'] = strip_tags($events_refund_pay[$k]['text']);
								 echo tep_draw_separator('pixel_trans.gif',10,10).tep_draw_pull_down_menu('events_payment', $events_refund_pay,$eInfo->events_payment); ?></td>
							</tr>
						</table>
						</td>
					</tr>
				<?php tep_content_title_bottom(); ?>	  
				
				<?php tep_content_title_top("Instructor"); ?>
				<tr>
					<td>
					<table border="0"  cellspacing="0" cellpadding="4" width="70%">
						<tr>
							
							<td align=left class="main" ><?php
							 echo TEXT_RATE_TYPE .tep_draw_separator('pixel_trans.gif',10,10) .tep_draw_pull_down_menu('instructors_rate_type',$rate_type_array,$eInfo->instructors_rate_type);
							 echo tep_draw_separator('pixel_trans.gif',20,10).TEXT_RATE .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('instructors_rate',number_format($eInfo->instructors_rate,2),'size=10 maxlength=10');
							 echo tep_draw_separator('pixel_trans.gif',20,10).TEXT_BASE_RATE .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('instructors_base_rate',number_format($eInfo->instructors_base_rate,2),'size=10 maxlength=10');?>
							</td>
						</tr>
						<tr>
							<td class="main" ><?php 
							echo TEXT_EVENTS_INSTRUCTOR .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_pull_down_menu('events_instructor', $instructor_array, $eInfo->events_instructor);
							echo tep_draw_separator('pixel_trans.gif',20,10).TEXT_EVENTS_BACKUP_INSTRUCTOR . tep_draw_separator('pixel_trans.gif',10,10).tep_draw_pull_down_menu('events_backup_instructor', $instructor_array, $eInfo->events_backup_instructor); ?>
							</td>
						</tr>
					</table>
					</td>
				</tr>
				<?php tep_content_title_bottom(); ?>	
				
			<script language="javascript"><!--
			updateGross();
			for(i=0;i< document.new_event.link_service.length;i++){
				if(document.new_event.link_service[i].checked){
					if(document.new_event.link_service[i].value=='S'){
						//document.getElementById('services').style.display="";
						//do_change(document.new_event.link_service[i]);
						init();
					}
					break;
				}
					
			}	
			//--></script>	  

			<script language=javascript>
				function doCheck(bolEnable){
					document.new_event.priority_vip.disabled=!bolEnable;
					document.new_event.session_style[0].disabled=!bolEnable;
					document.new_event.session_style[1].disabled=!bolEnable;
					document.new_event.priority_firstcome.disabled=!bolEnable;
					document.new_event.priority_custom.disabled=!bolEnable;
					document.new_event.priority_question.disabled=!bolEnable;
					document.new_event.waitsize_vip.disabled=!bolEnable;
					document.new_event.waitsize_firstcome.disabled=!bolEnable;
					document.new_event.waitsize_custom.disabled=!bolEnable;
					document.new_event.waitfee_vip.disabled=!bolEnable;
					document.new_event.waitfee_firstcome.disabled=!bolEnable;
					document.new_event.waitfee_custom.disabled=!bolEnable;
					document.new_event.events_forward_period.disabled=!bolEnable;    
					document.new_event.events_forward_length.disabled=!bolEnable;
					document.new_event.events_pending_period.disabled=!bolEnable;
				}
				function enableGroup(){
					var frm=document.new_event;
					frm.events_group_max.disabled=!frm.events_group_bookings.checked;
					frm.events_group_min.disabled=!frm.events_group_bookings.checked;
				}
			</script>
				 
				<?php tep_content_title_top("WaitingList"); ?>
				<tr>
					<td>
					<table border="0" width=100% cellspacing="0" cellpadding="4">
						<tr>
							<td class="main" align=left colspan="2"><?php echo tep_draw_checkbox_field('events_wait_list','Y',($eInfo->events_wait_list=='Y'?true:false),'','onClick="doCheck(this.checked)"') . TEXT_PRESENT_WAITLIST; ?></td>
						</tr>
						<tr>
							<td class="main" align="left" colspan="2"><?php echo TEXT_WAITLIST_STYLE . tep_draw_separator('pixel_trans.gif', '24', '1') . tep_draw_radio_field('session_style','S',($eInfo->session_style=="S"?true:false)) . TEXT_STYLE_SESSION . '&nbsp;' . tep_draw_radio_field('session_style','E',($eInfo->session_style=="E"?true:false)) . TEXT_STYLE_EVENT;?></td>
						</tr>
						<tr>
							<td colspan="2">
							<table border="0" width=100% cellspacing="0" cellpadding="4">
								<tr valign=top>
									<td class="main" align=left width=20%><?php echo '<b>' . HEADING_TYPE . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_PRIORITY . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_SIZE . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_FEE . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_APPLY_TO . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_DESCRIPTION . '</b>'; ?></td>
								</tr>	
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>

								<tr  valign=top>
									<td class="main"><?php echo TEXT_PRIORITY_VIP; ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_vip',$priority_array,((int)$eInfo->priority_vip!=0)?$eInfo->priority_vip:'1'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitsize_vip',$eInfo->waitsize_vip,'size=5 maxlength=6'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitfee_vip',$eInfo->waitfee_vip,'size=5 maxlength=6 onKeyUp="change_waitfee(this)"'); ?></td>
									<td class="main"><?php echo APPLY_TO_VIP ?></td>
									<td class="main" align=justify><?php echo DESCRIPTION_VIP ?></td>
								</tr>
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
							
								<tr  valign=top><td class="main"><?php echo TEXT_PRIORITY_FIRSTCOME; ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_firstcome',$priority_array,((int)$eInfo->priority_firstcome!=0)?$eInfo->priority_firstcome:'2'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitsize_firstcome',$eInfo->waitsize_firstcome,'size=5 maxlength=6'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitfee_firstcome',$eInfo->waitfee_firstcome,'size=5 maxlength=6 onKeyUp="change_waitfee(this)"'); ?></td>
									<td class="main"><?php echo APPLY_TO_FIRSTCOME ?></td>
									<td class="main" align=justify><?php echo DESCRIPTION_FIRSTCOME ?></td>
								</tr>
							
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
							
								<tr  valign=top>
									<td class="main"><?php echo TEXT_PRIORITY_CUSTOM; ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_custom',$priority_array,((int)$eInfo->priority_custom!=0)?$eInfo->priority_custom:'3');?></td>
									<td class="main"><?php echo tep_draw_input_field('waitsize_custom',$eInfo->waitsize_custom,'size=5 maxlength=6'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitfee_custom',$eInfo->waitfee_custom,'size=5 maxlength=6 onKeyUp="change_waitfee(this)"'); ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_question',$questions_array,$eInfo->priority_question); ?></td>
									<td class="main" align=justify><?php echo DESCRIPTION_CUSTOM ?></td>
								</tr>
							</table>
							</td>
						</tr>
					</table>
        			</td>
				</tr>
				<?php tep_content_title_bottom(); ?>	  
				
				<?php tep_content_title_top("Conditions"); ?>
				<tr>
					<td>
					<table border="0"  width=100% cellspacing="0" cellpadding="4">
						<tr>
							<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td class="main" width="150"><?php echo TEXT_PENDING_PERIOD . '&nbsp;'; ?></td>
									<td class="main"><?php echo tep_draw_input_field('events_pending_period',$eInfo->events_pending_period,'size=7 maxlength=6')  . TEXT_DAYS; ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td align=left class="main" valign="top"><?php echo TEXT_RENEWAL_START; ?></td>
									<td align=left class="main" valign="top"><?php echo tep_draw_pull_down_menu('events_renewal_start',$renewal_array,$eInfo->events_renewal_start); ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td align=left class="main" valign="top"><?php echo TEXT_RENEWAL_END; ?></td>
									<td align=left class="main" valign="top"><?php echo tep_draw_input_field('events_renewal_end',$eInfo->events_renewal_end,'size=10 maxlength=6')  . TEXT_DAYS; ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main"><?php echo TEXT_EVENTS_REFUND_PERCENTAGE; ?></td>
									<td class="main">
										<?php echo TEXT_EVENTS_REFUND_PERCENTAGE1 . '&nbsp;' . tep_draw_pull_down_menu('refund_percentage1',$events_percent_array,(tep_not_null($eInfo->refund_percentage1) ? $eInfo->refund_percentage1:'10')) . '%'
												. '&nbsp;' . TEXT_EVENTS_REFUND_PERCENTAGE2 . '&nbsp;' . tep_draw_pull_down_menu('refund_percentage2',$events_percent_array,(tep_not_null($eInfo->refund_percentage2) ? $eInfo->refund_percentage2:'30')) . '%'
												. '&nbsp;' . TEXT_EVENTS_REFUND_PERCENTAGE3 . '&nbsp;' . tep_draw_pull_down_menu('refund_percentage3',$events_percent_array,(tep_not_null($eInfo->refund_percentage3) ? $eInfo->refund_percentage3:'50')) . '%'; 
										?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td align="left" class="main" valign="top" width="150">&nbsp;</td>
									<td align="left" class="main" valign="top">
										<?php 	echo tep_draw_checkbox_field('session_gaps','Y',($eInfo->session_gaps=='Y'?true:false)) . '&nbsp;' . TEXT_SESSION_GAPS;
												echo '&nbsp;' . tep_draw_checkbox_field('session_reduction','Y',($eInfo->session_reduction=='Y'?true:false));
												echo '&nbsp;' . TEXT_SESSION_REDUCTION;
										?>
									</td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td align="left" class="main" valign="top" width="150">&nbsp;</td>
									<td class="main">
										<?php echo tep_draw_checkbox_field('events_forward_period','Y',($eInfo->events_forward_period=='Y'?true:false),'','onClick=""') . TEXT_FORWARD_PERIOD;
											echo '.&nbsp;&nbsp;&nbsp;' . TEXT_PERIOD_LENGTH . '&nbsp;' .  tep_draw_input_field('events_forward_length',$eInfo->events_forward_length,'size=7 maxlength=6') . TEXT_DAYS; ?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
								    <td align=left class="main"  valign="top" colspan="2">
								    <?php echo tep_draw_checkbox_field('events_group_bookings','Y',($eInfo->events_group_bookings=="Y"?true:false),false,'onClick="javascript:enableGroup();"') . TEXT_ALLOW_GROUP_BOOKINGS;?>
								    </td>
								</tr>
								<tr> 
								   <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
								    <td align=left class="main" valign="top"><?php echo TEXT_MIN_GROUP_SIZE ;?>
									<?php echo tep_draw_separator('pixel_trans.gif', '10', '5') . tep_draw_input_field('events_group_min',$eInfo->events_group_min,'size=7 maxlength=6');?></td>
									
								   <td align=left class="main" valign="top"><?php echo tep_draw_separator('pixel_trans.gif', '40', '10') . TEXT_MAX_GROUP_SIZE;?>
								  <?php echo tep_draw_separator('pixel_trans.gif', '10', '5') .tep_draw_input_field('events_group_max',$eInfo->events_group_max,'size=7 maxlength=6');?></td>
								</tr>
								<script lnguage="javascript">
									enableGroup();
								</script>
								<tr>
								    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr> 
								<tr>
									<td align=left class="main"  valign="top" width="150"><?php echo TEXT_CONDITION_DESC;?></td>
									<td class="main"><?php echo tep_draw_textarea_field('events_conditions','soft','100%',10,$eInfo->events_conditions); ?></td>
								</tr>
							</table>
							</td>
						</tr>
						
						
					</table>
					</td>
	  				<script language=javascript>
						doCheck(document.new_event.events_wait_list.checked);
					</script>
				</tr>
				<?php tep_content_title_bottom(); ?>
				
				<?php tep_content_title_top("Subscription"); ?>
				<tr>
					<td>
					<table border=0 cellpadding="4" cellspacing="0" width="50%">
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_SUBSCRIPTION_CATEGORIES; ?></td>
							<td class="main" width="200"><?php 
							$events_link=true;
							echo tep_draw_subscription_select_menu('subscription_categories_ids[]',$subscription_array, $subscription_categories_array_selected, 'size=10 id=subscription_categories_ids style="width:350"');
							?></td>
						</tr>
						<tr>
							<td class="main" nowrap="nowrap" width="150"><?php echo TEXT_SUBSCRIPTION_OVERBOOK_RESERVE; ?></td>
							<td class="main" align="left">
							<?php 
								echo tep_draw_input_field('subscription_overbook_reserve',(tep_not_null($eInfo->subscription_overbook_reserve) ? $eInfo->subscription_overbook_reserve:0),'size=10 maxlength=6');
							?>
							</td>
						</tr>
					</table>
					</td>
				</tr>	  
				<?php tep_content_title_bottom(); ?>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				
				
				
				<tr>
					<td class="main" align="right"><?php echo tep_draw_hidden_field('events_date_added', (tep_not_null($eInfo->events_date_added) ? $eInfo->events_date_added : getServerDate())) . tep_image_submit('button_save.gif', IMAGE_SAVE) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_MAINPAGE, 'top=1&mPath=2') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
				</tr>
		</table>
		
		
		</form>
       <?php if (HTML_AREA_WYSIWYG_DISABLE=='Enable') { 
		 for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
		    <script>initEditor('events_description[<?php echo $languages[$i]['id']; ?>]');</script>
		<?php  } 
		} ?>
<?php
  } elseif ($action == 'new_event_preview') {
    if (tep_not_null($HTTP_POST_VARS)) {
      $eInfo = new objectInfo($HTTP_POST_VARS);
      $events_name = $HTTP_POST_VARS['events_name'];
      $events_description = $HTTP_POST_VARS['events_description'];
      $events_url = $HTTP_POST_VARS['events_url'];
    } else {
	  // This is for Diveabout
      $event_query = tep_db_query("SELECT e.events_id, ed.language_id, ed.events_name, ed.events_description, ed.events_url, e.events_image, e.events_date_added, e.events_last_modified, e.events_date_available, e.events_status, e.events_fees, " . 
                                  "e.events_tax_class_id, e.events_start_time as start_time,time_format(e.events_start_time,'%h:%i %p') events_start_time,time_format(e.events_end_time,'%h:%i %p') as events_end_time,e.events_instructor,e.events_backup_instructor,e.events_location from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . 
				  " ed where e.events_id = ed.events_id and e.events_id = '" . (int)$HTTP_GET_VARS['eID'] . "' and language_id='" . $languages_id . "'");
      $event = tep_db_fetch_array($event_query);
	    $eInfo = new objectInfo($event);

      $events_image_name = $eInfo->events_image;
    }

    $form_action = (isset($HTTP_GET_VARS['eID'])) ? 'update_event' : 'insert_event';

    echo tep_draw_form($form_action, FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . (isset($HTTP_GET_VARS['eID']) ? '&eID=' . $HTTP_GET_VARS['eID'] : '') . '&action=' . $form_action, 'post', 'enctype="multipart/form-data"');

    $languages = tep_get_languages();
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
      if (isset($HTTP_GET_VARS['read']) && ($HTTP_GET_VARS['read'] == 'only')) {
        $eInfo->events_description = $eInfo->events_description;
        $eInfo->events_url = $eInfo->events_url;
		$event_location=tep_get_locations_name($eInfo->events_location);
		$eInfo->events_name = tep_get_events_name($HTTP_GET_VARS['eID']);
      } else {
        $eInfo->events_name = tep_db_prepare_input($events_description[$languages[$i]['name']]);
        $eInfo->events_description = tep_db_prepare_input($events_description[$languages[$i]['id']]);
        $eInfo->events_url = tep_db_prepare_input($events_url[$languages[$i]['id']]);
      }
?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . $eInfo->events_name; ?></td>
            <td class="pageHeading" align="right"><?php echo $currencies->format($eInfo->events_fees) ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo tep_image(DIR_WS_CATALOG_IMAGES . $events_image_name, $eInfo->events_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $eInfo->events_description; ?></td>
      </tr>
<?php
      if ($eInfo->events_url) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo sprintf(TEXT_EVENT_MORE_INFORMATION, $eInfo->events_url); ?></td>
      </tr>
<?php
      }
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<?php
      if ($eInfo->events_date_available > getServerDate()) {
?>
      <tr>
        <td align="center" class="smallText"><?php echo sprintf(TEXT_EVENT_DATE_AVAILABLE,tep_date_long($eInfo->events_date_available)); ?></td>
      </tr>
<?php
      } else {
?>
      <tr>
        <td align="center" class="smallText"><?php echo sprintf(TEXT_EVENT_DATE_ADDED, tep_date_long($eInfo->events_date_added)); ?></td>
      </tr>
<?php
      }
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<?php
    }

    if (isset($HTTP_GET_VARS['read']) && ($HTTP_GET_VARS['read'] == 'only')) {
      if (isset($HTTP_GET_VARS['origin'])) {
        $pos_params = strpos($HTTP_GET_VARS['origin'], '?', 0);
        if ($pos_params != false) {
          $back_url = substr($HTTP_GET_VARS['origin'], 0, $pos_params);
          $back_url_params = substr($HTTP_GET_VARS['origin'], $pos_params + 1);
        } else {
          $back_url = $HTTP_GET_VARS['origin'];
          $back_url_params = '';
        }
      } else {
        $back_url = FILENAME_EVENTS_CATEGORIES;
        $back_url_params = 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id;
      }
?>
      <tr>
        <td align="right"><?php echo '<a href="' . tep_href_link($back_url, $back_url_params, 'NONSSL') . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
      </tr>
<?php
    } else {
?>
      <tr>
        <td align="right" class="smallText">
<?php
/////////////////////////////////////////////////////////////////////
// BOF: WebMakers.com Added: Original Code No longer used
// Code has been left in to show how additional events_descriptions could be added
if (false) {
/* Re-Post all POST'ed variables */
    reset($HTTP_POST_VARS);
      while (list($key, $value) = each($HTTP_POST_VARS)) {
        if (!is_array($HTTP_POST_VARS[$key])) {
          echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
        }
      }
      $languages = tep_get_languages();
      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
        echo tep_draw_hidden_field('events_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($events_name[$languages[$i]['id']])));
        echo tep_draw_hidden_field('events_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($events_description[$languages[$i]['id']])));
        echo tep_draw_hidden_field('events_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($events_url[$languages[$i]['id']])));
      }
} // false
// EOF: WebMakers.com Added: Original Code
/////////////////////////////////////////////////////////////////////
?>

<?php
/////////////////////////////////////////////////////////////////////
// BOF: WebMakers.com Added: Modified to include Attributes Code
/* Re-Post all POST'ed variables */
      reset($HTTP_POST_VARS);
      while (list($key, $value) = each($HTTP_POST_VARS)) {
        if (is_array($value)) {
          while (list($k, $v) = each($value)) {
            echo tep_draw_hidden_field($key . '[' . $k . ']', htmlspecialchars(stripslashes($v)));
          }
        } else {
          echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
        }
      }
// EOF: WebMakers.com Added: Modified to include Attributes Code
/////////////////////////////////////////////////////////////////////
      echo tep_draw_hidden_field('events_image', stripslashes($events_image_name));

      echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';

      if (isset($HTTP_GET_VARS['eID'])) {
        echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
      } else {
        echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
      }
      echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . (isset($HTTP_GET_VARS['eID']) ? '&eID=' . $HTTP_GET_VARS['eID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
?></td>
      </tr>
    </table></form>
<?php
    }
  } else {
?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
		    <!-- <td class="pageHeading"><?php //echo HEADING_TITLE; ?></td>
            <!--<td class="pageHeading" align="right"><?php //echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>!-->
            <td class="pageHeading"><?php echo tep_output_rev_generated_events_category_path($current_events_category_id); ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td class="smallText" align="right">
<?php
    echo tep_draw_form('search', FILENAME_EVENTS_CATEGORIES, '', 'get');
    echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search');
    echo '</form>';
?>
                </td>
              </tr>
              <tr>
                <td class="smallText" align="right">
<?php
    echo tep_draw_form('goto', FILENAME_EVENTS_CATEGORIES, '', 'get');
    echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('ecPath', tep_get_events_category_tree(), $current_events_category_id, 'onChange="this.form.submit();"');
    echo '</form>';
?>
                </td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_EVENTS_CATEGORIES_EVENTS; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_STATUS; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
<?php
    $events_categories_count = 0;
    $rows = 0;
    if (isset($HTTP_GET_VARS['search'])) {
      $search = tep_db_prepare_input($HTTP_GET_VARS['search']);

      $events_categories_query = tep_db_query("SELECT e.events_categories_id, ed.events_categories_name, e.events_categories_image, e.parent_id, e.sort_order, e.date_added, e.last_modified from " . TABLE_EVENTS_CATEGORIES . " e, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ed where e.events_categories_id = ed.events_categories_id and ed.language_id = '" . (int)$languages_id . "' and ed.events_categories_name like '%" . tep_db_input($search) . "%' order by e.sort_order, ed.events_categories_name");
    } else {
      $events_categories_query = tep_db_query("SELECT e.events_categories_id, ed.events_categories_name, e.events_categories_image, e.parent_id, e.sort_order, e.date_added, e.last_modified from " . TABLE_EVENTS_CATEGORIES . " e, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ed where e.events_categories_id = ed.events_categories_id and e.parent_id = '" . (int)$current_events_category_id . "' and ed.language_id = '" . (int)$languages_id . "' order by e.sort_order, ed.events_categories_name");
    }
    while ($events_categories = tep_db_fetch_array($events_categories_query)) {
      $events_categories_count++;
      $rows++;
// Get parent_id for subcategories if search
      if (isset($HTTP_GET_VARS['search'])) $ecPath=$events_categories['parent_id'];

      if ((!isset($HTTP_GET_VARS['ecID']) && !isset($HTTP_GET_VARS['eID']) || (isset($HTTP_GET_VARS['ecID']) && ($HTTP_GET_VARS['ecID'] == $events_categories['events_categories_id']))) && !isset($ecInfo) && (substr($action, 0, 3) != 'new')) {
        $events_category_childs = array('childs_count' => tep_childs_in_events_category_count($events_categories['events_categories_id']));
        $events_category_events = array('events_count' => tep_events_in_events_category_count($events_categories['events_categories_id']));
        $ecInfo_array = array_merge($events_categories, $events_category_childs, $events_category_events);
        $ecInfo = new objectInfo($ecInfo_array);
      }
 
      if (isset($ecInfo) && is_object($ecInfo) && ($events_categories['events_categories_id'] == $ecInfo->events_categories_id) ) {
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $events_categories['events_categories_id'] . '&action=new_events_category_preview&read=only') . '\'">' . "\n";
      } else {
        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $events_categories['events_categories_id']) . '\'">' . "\n";
      }
	  
?>
                <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, tep_get_events_path($events_categories['events_categories_id'])) . '">' . tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER) . '</a>&nbsp;<b>' . $events_categories['events_categories_name'] . '</b>'; ?></td>
                <td class="dataTableContent" align="center">&nbsp;</td>
                <td class="dataTableContent" align="right"><?php if (isset($ecInfo) && is_object($ecInfo) && ($events_categories['events_categories_id'] == $ecInfo->events_categories_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $events_categories['events_categories_id'] . '&action=new_events_category_preview&read=only') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }

    $events_count = 0;
 	  // This is for Diveabout
   if (isset($HTTP_GET_VARS['search'])) {
      $events_query = tep_db_query("SELECT e.events_id, ed.events_name, e.events_image, e.events_date_added, e.events_last_modified, e.events_date_available, e.events_status, e2c.events_categories_id,e.events_start_time,e.events_location from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " e2c, " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed  where e.events_id = e2c.events_id and e.events_id = ed.events_id and ed.language_id = '" . (int)$languages_id . "' and ed.events_name like '%" . tep_db_input($search) . "%' order by ed.events_name");
    } else {
      $events_query = tep_db_query("SELECT e.events_id, ed.events_name, e.events_image, e.events_date_added, e.events_last_modified, e.events_date_available, e.events_status, e.events_start_time,e.events_location from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " e2c, " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed where e.events_id = e2c.events_id and e.events_id=ed.events_id and ed.language_id = '" . (int)$languages_id . "' and e2c.events_categories_id = '" . (int)$current_events_category_id . "' order by ed.events_name");
    }
    while ($events = tep_db_fetch_array($events_query)) {
      $events_count++;
      $rows++;

// Get categories_id for event if search
      if (isset($HTTP_GET_VARS['search'])) $ecPath = $events['events_categories_id'];

      if ( (!isset($HTTP_GET_VARS['eID']) && !isset($HTTP_GET_VARS['ecID']) || (isset($HTTP_GET_VARS['eID']) && ($HTTP_GET_VARS['eID'] == $events['events_id']))) && !isset($eInfo) && !isset($ecInfo) && (substr($action, 0, 3) != 'new')) {
	  	// to check if this event can be deleted
		$events_link_query=tep_db_query("select count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id='" . $events["events_id"] . "'");
		$events_link=tep_db_fetch_array($events_link_query);
        $events_sessions = array('sessions_count' => tep_sessions_in_events_count($events['events_id']),'delete_event'=>true);
		if ($events_sessions['sessions_count']>0 && (int)$events_link["total"]<=1){
			$events_sessions['delete_event']=false;
		}
        $ecInfo_array = array_merge($events, $events_sessions);
        $eInfo = new objectInfo($ecInfo_array);
      }
		
		$event_name=tep_get_events_display_text($events["events_name"],"","");
		
      if (isset($eInfo) && is_object($eInfo) && ($events['events_id'] == $eInfo->events_id)) {
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $events['events_id'] . '&action=new_event_preview&read=only') . '\'">' . "\n";
      } else {
        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $events['events_id']) . '\'">' . "\n";
      }
?>
                <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_SESSIONS, 'ecPath=' . $ecPath . '&eID=' . $events['events_id']) . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;' . $event_name; ?></td>
                <td class="dataTableContent" align="left">
<?php
      if ($events['events_status'] == '1') {
        echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'action=setflag&flag=0&eID=' . $events['events_id'] . '&ecPath=' . $ecPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'action=setflag&flag=1&eID=' . $events['events_id'] . '&ecPath=' . $ecPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
		if ($events['events_status']==2){
			echo '&nbsp;' . tep_image(DIR_WS_ICONS . 'warning.gif',IMAGE_HIDE_START_EVENT);
		} else if($events['events_status']>=3) {
			echo '&nbsp;' . tep_image(DIR_WS_ICONS . 'warning.gif',IMAGE_HIDE_END_EVENT);
		}
      }
?></td>
                <td class="dataTableContent" align="right"><?php if (isset($eInfo) && is_object($eInfo) && ($events['events_id'] == $eInfo->events_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $events['events_id']  . '&action=new_event_preview&read=only') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }

    $ecPath_back = '';
    if (sizeof($ecPath_array) > 0) {
      for ($i=0, $n=sizeof($ecPath_array)-1; $i<$n; $i++) {
        if (empty($ecPath_back)) {
          $ecPath_back .= $ecPath_array[$i];
        } else {
          $ecPath_back .= '_' . $ecPath_array[$i];
        }
      }
    }
    
    $ecPath_back = (tep_not_null($ecPath_back)) ? 'ecPath=' . $ecPath_back . '&' : '';
?>
              <tr>
                <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText">
					<?php echo TEXT_EVENTS_CATEGORIES . '&nbsp;' . $events_categories_count . '<br>' . TEXT_EVENTS . '&nbsp;' . $events_count; ?>
					</td>
                    <td align="right" class="smallText">
					<?php if (sizeof($ecPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, $ecPath_back . 'ecID=' . $current_events_category_id) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;'; if (!isset($HTTP_GET_VARS['search'])) echo '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&action=new_events_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&action=new_event') . '">' . tep_image_button('button_new_event.gif', IMAGE_NEW_EVENT) . '</a>'; ?>&nbsp;
					</td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
<?php
    $heading = array();
    $contents = array();
    switch ($action) {
      case 'new_events_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_EVENTS_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('neweventscategory', FILENAME_EVENTS_CATEGORIES, 'action=insert_events_category&ecPath=' . $ecPath, 'post', 'enctype="multipart/form-data" onSubmit="javascript:alert(this.action)"'));
        $contents[] = array('text' => TEXT_NEW_EVENTS_CATEGORY_INTRO);

        $events_category_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $events_category_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('events_categories_name[' . $languages[$i]['id'] . ']');
        }

        $contents[] = array('text' => '<br>' . TEXT_EVENTS_CATEGORIES_NAME . $events_category_inputs_string);
        $contents[] = array('text' => '<br>' . TEXT_EVENTS_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('events_categories_image'));
        $contents[] = array('text' => '<br>' . TEXT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', '', 'size="2"'));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'edit_events_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_EVENTS_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('events_categories', FILENAME_EVENTS_CATEGORIES, 'action=update_events_category&ecPath=' . $ecPath, 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('events_categories_id', $ecInfo->events_categories_id));
        $contents[] = array('text' => TEXT_EDIT_INTRO);

        $events_category_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $events_category_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('events_categories_name[' . $languages[$i]['id'] . ']', tep_get_events_category_name($ecInfo->events_categories_id, $languages[$i]['id']));
        }

        $contents[] = array('text' => '<br>' . TEXT_EDIT_EVENTS_CATEGORIES_NAME . $events_category_inputs_string);
        $contents[] = array('text' => '<br>' . tep_image(DIR_WS_CATALOG_IMAGES . $ecInfo->categories_image, $ecInfo->categories_name) . '<br>' . DIR_WS_CATALOG_IMAGES . '<br><b>' . $ecInfo->events_categories_image . '</b>');
        $contents[] = array('text' => '<br>' . TEXT_EDIT_EVENTS_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('events_categories_image'));
        $contents[] = array('text' => '<br>' . TEXT_EDIT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', $ecInfo->sort_order, 'size="2"'));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'delete_events_category':
        $err_delete=false;
        if ($ecInfo->events_count>0 || $ecInfo->childs_count>0)
	   $err_delete=true;
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_EVENTS_CATEGORY . '</b>');
        $contents = array('form' => tep_draw_form('events_categories', FILENAME_EVENTS_CATEGORIES, 'action=delete_events_category_confirm&ecPath=' . $ecPath) . tep_draw_hidden_field('events_categories_id', $ecInfo->events_categories_id));
        $contents[] = array('text' => TEXT_DELETE_EVENTS_CATEGORY_INTRO);
        $contents[] = array('text' => '<br><b>' . $ecInfo->events_categories_name . '</b>');
        if ($ecInfo->childs_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_CHILDS, $ecInfo->childs_count));
        if ($ecInfo->events_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_EVENTS, $ecInfo->events_count));
        $contents[] = array('align' => 'center', 'text' => '<br>' . ($err_delete==false?tep_image_submit('button_delete.gif', IMAGE_DELETE):'') . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'move_events_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_EVENTS_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('events_categories', FILENAME_EVENTS_CATEGORIES, 'action=move_events_category_confirm&ecPath=' . $ecPath) . tep_draw_hidden_field('events_categories_id', $ecInfo->events_categories_id));
        $contents[] = array('text' => sprintf(TEXT_MOVE_EVENTS_CATEGORIES_INTRO, $cInfo->events_categories_name));
        $contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $ecInfo->events_categories_name) . '<br>' . tep_draw_pull_down_menu('move_to_events_category_id', tep_get_events_category_tree(), $current_events_category_id));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'delete_event':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_EVENT . '</b>');

        $contents = array('form' => tep_draw_form('events', FILENAME_EVENTS_CATEGORIES, 'action=delete_event_confirm&ecPath=' . $ecPath) . tep_draw_hidden_field('events_id', $eInfo->events_id));
        $contents[] = array('text' => TEXT_DELETE_EVENT_INTRO);
        $contents[] = array('text' => '<br><b>' . $eInfo->events_name . '</b>');
        if ($eInfo->delete_event){
        $events_categories_string = '';
        $events_categories = tep_generate_events_category_path($eInfo->events_id, 'event');
        for ($i = 0, $n = sizeof($events_categories); $i < $n; $i++) {
          $events_category_path = '';
          for ($j = 0, $k = sizeof($events_categories[$i]); $j < $k; $j++) {
            $events_category_path .= $events_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
          }
          $events_category_path = substr($events_category_path, 0, -16);
		  if ($eInfo->sessions_count>0 && $i==0)
			  $events_categories_string .= $events_category_path . '<br>';
		  else
	          $events_categories_string .= tep_draw_checkbox_field('events_categories[]', $events_categories[$i][sizeof($events_categories[$i])-1]['id'], true) . '&nbsp;' . $events_category_path . '<br>';
        }
        $events_categories_string = substr($events_categories_string, 0, -4);

        $contents[] = array('text' => '<br>' . $events_categories_string);
	$err_delete=false;}
	else{
	  $contents[]=array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_SESSIONS,$eInfo->sessions_count));
	  $err_delete=true;}
        $contents[] = array('align' => 'center', 'text' => '<br>' . ($err_delete==false?tep_image_submit('button_delete.gif', IMAGE_DELETE):'') . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'move_event':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_EVENT . '</b>');

        $contents = array('form' => tep_draw_form('events', FILENAME_EVENTS_CATEGORIES, 'action=move_event_confirm&ecPath=' . $ecPath) . tep_draw_hidden_field('events_id', $eInfo->events_id));
        $contents[] = array('text' => sprintf(TEXT_MOVE_EVENTS_INTRO, $eInfo->events_name));
        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_EVENTS_CATEGORIES . '<br><b>' . tep_output_generated_events_category_path($eInfo->events_id, 'event') . '</b>');
        $contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $eInfo->events_name) . '<br>' . tep_draw_pull_down_menu('move_to_events_category_id', tep_get_events_category_tree(), $current_events_category_id));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'copy_to':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_COPY_TO . '</b>');

        $contents = array('form' => tep_draw_form('copy_to', FILENAME_EVENTS_CATEGORIES, 'action=copy_to_confirm&ecPath=' . $ecPath) . tep_draw_hidden_field('events_id', $eInfo->events_id));
        $contents[] = array('text' => TEXT_INFO_COPY_TO_INTRO);
        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_EVENTS_CATEGORIES . '<br><b>' . tep_output_generated_events_category_path($eInfo->events_id, 'event') . '</b>');
        $contents[] = array('text' => '<br>' . TEXT_EVENTS_CATEGORIES . '<br>' . tep_draw_pull_down_menu('events_categories_id', tep_get_events_category_tree(), $current_events_category_id));
        $contents[] = array('text' => '<br>' . TEXT_HOW_TO_COPY . '<br>' . tep_draw_radio_field('copy_as', 'link', true) . ' ' . TEXT_COPY_AS_LINK . '<br>' . tep_draw_radio_field('copy_as', 'duplicate') . ' ' . TEXT_COPY_AS_DUPLICATE);
        $contents[] = array('text' => '<br>' . tep_draw_checkbox_field('copy_sessions', 'yes', true) . ' ' . TEXT_COPY_SESSIONS);
        $contents[] = array('text' => tep_draw_checkbox_field('copy_messages', 'yes') . ' ' . TEXT_COPY_MESSAGES);
        $contents[] = array('text' => tep_draw_checkbox_field('copy_surveys', 'yes') . ' ' . TEXT_COPY_SURVEYS);
		$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_copy.gif', IMAGE_COPY) . ' <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      default:
        if ($rows>0) {
          if (isset($ecInfo) && is_object($ecInfo)) { // category info box contents
            $heading[] = array('text' => '<b>' . $ecInfo->events_categories_name . '</b>');
            $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id . '&action=edit_events_category') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id . '&action=delete_events_category') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) 
	                         . '</a> <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&ecID=' . $ecInfo->events_categories_id . '&action=move_events_category') . '">' . tep_image_button('button_move.gif',IMAGE_MOVE) . '</a>');
            $contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . format_date($ecInfo->date_added));
            if (tep_not_null($ecInfo->last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . format_date($ecInfo->last_modified));
            $contents[] = array('text' => '<br>' . tep_info_image($ecInfo->events_categories_image, $ecInfo->events_categories_name, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT) . '<br>' . $ecInfo->events_categories_image);
            $contents[] = array('text' => '<br>' . TEXT_SUBEVENTS_CATEGORIES . ' ' . $ecInfo->childs_count . '<br>' . TEXT_EVENTS . ' ' . $ecInfo->events_count);
          } elseif (isset($eInfo) && is_object($eInfo)) { // event info box contents
            $heading[] = array('text' => '<b>' . tep_get_events_name($eInfo->events_id, $languages_id) . '</b>');
            $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id . '&action=new_event') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id . '&action=delete_event') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a><br>' 
	                  . '<a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id . '&action=move_event') . '">' . tep_image_button('button_move.gif', IMAGE_MOVE) . '</a> <a href="' . tep_href_link(FILENAME_EVENTS_CATEGORIES, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id . '&action=copy_to') . '">' . tep_image_button('button_copy_to.gif', IMAGE_COPY_TO) . '</a><p>'
			  . '<a href="' . tep_href_link(FILENAME_SESSIONS, 'ecPath=' . $ecPath . '&eID=' . $eInfo->events_id) . '">' . tep_image_button('button_sessions.gif', IMAGE_SESSIONS) . '</a>&nbsp;'
                          . '<a href="' . tep_href_link(FILENAME_WAITLISTS,'&events_id=' . $eInfo->events_id) . '">' . tep_image_button('button_waitlists.gif', IMAGE_WAITLISTS) . '</a><br>'
			  . '<a href="' . tep_href_link(FILENAME_EVENTS_MESSAGES, 'events_id=' . $eInfo->events_id) . '">' . tep_image_button('button_messages.gif', IMAGE_MESSAGES) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_SMS_MESSAGES, 'events_id=' . $eInfo->events_id) . '">' . tep_image_button('button_sms.gif', IMAGE_SMS_MESSAGES) . '</a><p>');
            $contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . format_date($eInfo->events_date_added));
            if (tep_not_null($eInfo->events_last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . format_date($eInfo->events_last_modified));
            if (getServerDate() < $eInfo->events_date_available) $contents[] = array('text' => TEXT_DATE_AVAILABLE . ' ' . format_date($eInfo->events_date_available));
            $contents[] = array('text' => '<br>' . tep_info_image($eInfo->events_image, $eInfo->events_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br>' . $eInfo->events_image);
          }
        } else { // create events category/event info
          $heading[] = array('text' => '<b>' . EMPTY_EVENTS_CATEGORY . '</b>');

          $contents[] = array('text' => TEXT_NO_CHILD_EVENTS_CATEGORIES_OR_EVENTS);
        }
        break;
    }

    if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
      echo '            <td width="25%" valign="top">' . "\n";

      $box = new box;
      echo $box->infoBox($heading, $contents);

      echo '            </td>' . "\n";
    }
?>
          </tr>
        </table></td>
      </tr>
    </table>
<?php
  }
?>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<script language="javascript" type="text/javascript">
	function validate_image(){
		var image_types=Array(".png",".jpg",".jpeg",".gif");
		var frm = document.new_events_category;
		var error = "";
		if (frm.elements["events_categories_image"].value!="" && !check_mime_type(frm.elements["events_categories_image"],image_types)){
			error="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
		}
		if(error!=""){
			alert(error);
			return false;
		}
		return true;
	}
	
</script>
</td></tr></table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
