<?php
/*

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

  Copyright (c) 2005 osCommRes

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

Copyright 2007 ZacWare Pty. Ltd 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	tep_get_last_access_file();require(DIR_WS_CLASSES . 'currencies.php');
	$currencies = new currencies();
	$current_date=getServerDate();
	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

	if (tep_not_null($action)) {
	switch ($action) {
		case 'new_subscription_category':
		case 'edit_subscription_category':
			if (ALLOW_CATEGORY_DESCRIPTIONS == 'true')
				$HTTP_GET_VARS['action']=$HTTP_GET_VARS['action'] . '_ACD';
			break;
		case 'new_subscription_category':
		case 'edit_subscription_category':
			if (ALLOW_CATEGORY_DESCRIPTIONS == 'true')
				$HTTP_GET_VARS['action']=$HTTP_GET_VARS['action'] . '_ACD';
			break;
		case 'insert_subscription_category':
		case 'update_subscription_category':
			if ( ($HTTP_POST_VARS['edit_x']) || ($HTTP_POST_VARS['edit_y']) ) {
				$HTTP_GET_VARS['action'] = 'edit_subscription_category_ACD';
			} else {
			
				if (isset($HTTP_POST_VARS['subscription_categories_id'])) $subscription_categories_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_id']);
			
				if ($subscription_categories_id == '') {
					$subscription_categories_id = tep_db_prepare_input($HTTP_GET_VARS['sucID']);
				}


				$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_subscription_category') {
					$insert_sql_data = array(	'parent_id' => $current_subscription_category_id,
												'date_added' => 'now()');
				
					$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				
					tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES, $sql_data_array);
				
					$subscription_categories_id = tep_db_insert_id();
					
				} elseif ($action == 'update_subscription_category') {
					
					$update_sql_data = array('last_modified' => 'now()');
				
					$sql_data_array = array_merge($sql_data_array, $update_sql_data);
				
					tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES, $sql_data_array, 'update', "subscription_categories_id = '" . (int)$subscription_categories_id . "'");
				}

				$languages = tep_get_languages();
				for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
					$subscription_categories_name_array = $HTTP_POST_VARS['subscription_categories_name'];
					$language_id = $languages[$i]['id'];
					$sql_data_array = array('subscription_categories_name' => tep_db_prepare_input($subscription_categories_name_array[$language_id]));
								
					if (ALLOW_CATEGORY_DESCRIPTIONS == 'true') {
						$sql_data_array = array('subscription_categories_name' => tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_name'][$language_id]),
												'subscription_categories_heading_title' => tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_heading_title'][$language_id]),
												'subscription_categories_description' => tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_description'][$language_id]));
					}
					if ($action == 'insert_subscription_category') {
						$insert_sql_data = array(	'subscription_categories_id' => $subscription_categories_id,
													'language_id' => $languages[$i]['id']);
					
						$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
					
						tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION, $sql_data_array);
					} elseif ($action == 'update_subscription_category') {
						tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "subscription_categories_id = '" . (int)$subscription_categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
					}
				}
				if (ALLOW_CATEGORY_DESCRIPTIONS == 'true') {
					tep_db_query("update " . TABLE_SUBSCRIPTION_CATEGORIES . " set subscription_categories_image = '" . $HTTP_POST_VARS['subscription_categories_image'] . "' where subscription_categories_id = '" .  (int)tep_db_input($subscription_categories_id) . "'");
					$subscription_categories_image = '';
				} else {
					if ($subscription_categories_image = new upload('subscription_categories_image', DIR_FS_CATALOG_IMAGES)) {
						tep_db_query("update " . TABLE_SUBSCRIPTION_CATEGORIES . " set subscription_categories_image = '" . tep_db_input($subscription_categories_image->filename) . "' where subscription_categories_id = '" . (int)$subscription_categories_id . "'");
					}
				}

				if (isset($sucPath))
					tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $subscription_categories_id));
				else
					tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucID=' . $subscription_categories_id));

        	}
			break;
		case 'delete_subscription_category_confirm':
			if (isset($HTTP_POST_VARS['subscription_categories_id'])) {

				$subscription_categories_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_id']);
				$subscription_categories = tep_get_subscription_category_tree($subscription_categories_id, '', '0', '', true);
				$subscription = array();
				$subscription_delete = array();

				for ($i=0, $n=sizeof($subscription_categories); $i<$n; $i++) {
					$subscription_ids_query = tep_db_query("SELECT subscription_id from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_categories_id = '" . (int)$subscription_categories[$i]['id'] . "'");
					while ($subscription_ids = tep_db_fetch_array($subscription_ids_query)) {
						$subscription[$subscription_ids['subscription_id']]['subscription_categories'][] = $subscription_categories[$i]['id'];
					}
				}

				reset($subscription);
				while (list($key, $value) = each($subscription)) {
					$subscription_category_ids = '';
				
					for ($i=0, $n=sizeof($value['subscription_categories']); $i<$n; $i++) {
						$subscription_category_ids .= "'" . (int)$subscription['subscription_categories'][$i] . "', ";
					}
					$subscription_category_ids = substr($subscription_category_ids, 0, -2);
					$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$key . "' and subscription_categories_id not in (" . $subscription_category_ids . ")");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') {
						$subscription_delete[$key] = $key;
					}
				}

				tep_set_time_limit(0);


				for ($i=0, $n=sizeof($subscription_categories); $i<$n; $i++) {
					tep_remove_subscription_category($subscription_categories[$i]['id']);
				}

				reset($subscription_delete);
				while (list($key) = each($subscription_delete)) {
					tep_remove_subscription($key);
				}
			}
		
				tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES,'sucPath=' . $sucPath));
				break;
		case 'move_subscription_category_confirm':
				if (isset($HTTP_POST_VARS['subscription_categories_id']) && ($HTTP_POST_VARS['subscription_categories_id'] != $HTTP_POST_VARS['move_to_subscription_category_id'])) {
						$subscription_categories_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_id']);
						$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_subscription_category_id']);
			
						$path = explode('_', tep_get_generated_subscription_category_path_ids($new_parent_id));
						
						if (in_array($subscription_categories_id, $path)) {
							$messageStack->add_session(ERROR_CANNOT_MOVE_SUBSCRIPTION_TO_PARENT, 'error');
						
							tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $subscription_categories_id));
						} else {
							tep_db_query("update " . TABLE_SUBSCRIPTION_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified = now() where subscription_categories_id = '" . (int)$subscription_categories_id . "'");
			
							tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucID=' . $subscription_categories_id));
						}
				}
				break;
			case 'new_subscription':
			case 'edit_subscription':
				if (ALLOW_CATEGORY_DESCRIPTIONS == 'true')
					$HTTP_GET_VARS['action']=$HTTP_GET_VARS['action'] . '_ACD';
				break;

			case 'setflag':
				if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
					if (isset($HTTP_GET_VARS['suID'])) {
						tep_set_subscription_status($HTTP_GET_VARS['suID'], $HTTP_GET_VARS['flag']);
					}
				
				}
				tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . 'suID=' . $HTTP_GET_VARS['suID']));
				break;
			case 'insert_subscription':
			case 'update_subscription':
				//PR Algozone: copy image only if modified
				$subscription_image = new upload('subscription_image');
				$subscription_image->set_destination(DIR_FS_CATALOG_IMAGES);
				if ($subscription_image->parse() && $subscription_image->save()) {
					$subscription_image_name = $subscription_image->filename;
				} else {
					$subscription_image_name = (isset($HTTP_POST_VARS['subscription_previous_image']) ? $HTTP_POST_VARS['subscription_previous_image'] : '');
				}

				if (isset($HTTP_POST_VARS['edit_x']) || isset($HTTP_POST_VARS['edit_y'])) {
					$HTTP_GET_VARS['action'] = 'edit_subscription_ACD';
				} else {	
					if (isset($HTTP_GET_VARS['suID'])) $subscription_id = tep_db_prepare_input($HTTP_GET_VARS['suID']);
						$subscription_date_available = tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['subscription_date_available']));
											
						$subscription_finish_date = (isset($HTTP_POST_VARS["subscription_finish_date"])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS["subscription_finish_date"])):'0000-00-00');
						$subscription_start_date = (isset($HTTP_POST_VARS["subscription_start_date"])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS["subscription_start_date"])):'0000-00-00');
						$subscription_latest_start_date = (isset($HTTP_POST_VARS["subscription_latest_start_date"])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS["subscription_latest_start_date"])):'0000-00-00');
						$subscription_period = (isset($HTTP_POST_VARS["subscription_period"])?$HTTP_POST_VARS["subscription_period"]:0);
						$subscription_date_type = (isset($HTTP_POST_VARS["subscription_date_type"])?$HTTP_POST_VARS["subscription_date_type"]:'F');
						if($subscription_date_type=='F')$subscription_latest_start_date='0000-00-00';

						$subscription_group=(isset($HTTP_POST_VARS["subscription_group"])?$HTTP_POST_VARS["subscription_group"]:'');
						$subscription_type=(isset($HTTP_POST_VARS["subscription_type"])?$HTTP_POST_VARS["subscription_type"]:'T');
						//subscription type
							$deliveries=(int)isset($HTTP_POST_VARS['txt_deliveries'])?$HTTP_POST_VARS['txt_deliveries']:0; 
							$deliveries_name=(int)isset($HTTP_POST_VARS['txt_deliveries_name'])?$HTTP_POST_VARS['txt_deliveries_name']:'Deliveries'; 
							if($subscription_type=='C')	$deliveries_perday=(int)isset($HTTP_POST_VARS['txt_perday'])?$HTTP_POST_VARS['txt_perday']:0;
						//subscription type
						$emarketing_on_renewal='S';
						$emarketing_on_renewal=(($HTTP_POST_VARS['emarket_renew_continue']=='1')?'C':'S');
						//free trial
						$subscription_free_trial=(isset($HTTP_POST_VARS["subscription_free_trial"])?'Y':'N');
						$subscription_free_days=1;
						if ($subscription_free_trial=='Y') $subscription_free_days=(int)$HTTP_POST_VARS["subscription_free_days"];
						$wallet_payment=(isset($HTTP_POST_VARS["wallet_payment"])?'Y':'N');
						$periodic_payment=(isset($HTTP_POST_VARS["periodic_payment"])?'Y':'N');
						$periodic_days=0;
						if ($periodic_payment=='Y') $periodic_days=(int)$HTTP_POST_VARS["periodic_days"];
						$periodic_type=(isset($HTTP_POST_VARS['periodic_type'])?$HTTP_POST_VARS['periodic_type']:'A');
						$pack_slip_content="";
						if($HTTP_POST_VARS['pack_slip']==true)	
							$pack_slip_content=tep_db_prepare_input($HTTP_POST_VARS['message_text']);
							
					    $subscription_cost_net=$HTTP_POST_VARS['subscription_costs_net'];
						if($subscription_cost_net=='') $subscription_cost_net='0';
						
						if($deliveries_perday=='') $deliveries_perday='0';
						
						$sql_data_array = array('subscription_date_available' => $subscription_date_available,
												'subscription_status' => tep_db_prepare_input($HTTP_POST_VARS['subscription_status']),
												'subscription_conditions'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_conditions']),
												'subscription_costs'=>tep_db_prepare_input($subscription_cost_net),
												'subscription_type'=>tep_db_prepare_input($subscription_type),
												'subscription_tax_class_id'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_tax_class_id']),
												'subscription_renewal_start'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_renewal_start']),
												'subscription_renewal_end'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_renewal_end']),
												'subscription_pending_period'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_pending_period']),
												//'subscription_period'=>tep_db_prepare_input($subscription_period),
												'subscription_group'=>tep_db_prepare_input($subscription_group),
												'subscription_packing_slip'=>$pack_slip_content,
												'subscription_free_trial'=>$subscription_free_trial,
												'emarketing_on_renewal'=>$emarketing_on_renewal,
												'subscription_free_days'=>$subscription_free_days,
												'wallet_payment'=>$wallet_payment,
												'periodic_payment'=>$periodic_payment,
												'periodic_days'=>$periodic_days,
												'periodic_type'=>$periodic_type,
												'deliveries'=>$deliveries,
												'deliveries_name'=>$deliveries_name,
												'deliveries_perday'=>$deliveries_perday,
												'subscription_start_date'=>$subscription_start_date,
												'subscription_finish_date'=>$subscription_finish_date,
												'subscription_latest_start_date'=>$subscription_latest_start_date,
												'subscription_period'=>$subscription_period,
												'subscription_date_type'=>$subscription_date_type,
												);
						if (isset($subscription_image_name) && tep_not_null($subscription_image_name) && ($subscription_image_name != 'none')) {
							$sql_data_array['subscription_image'] = tep_db_prepare_input($subscription_image_name);
						}
						if ($action == 'insert_subscription') {
							$insert_sql_data = array('subscription_date_added' => 'now()');
						
							$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
						
							tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array);
							$subscription_id = tep_db_insert_id();
						} elseif ($action == 'update_subscription') {
							$update_sql_data = array('subscription_last_modified' => 'now()');
						
							$sql_data_array = array_merge($sql_data_array, $update_sql_data);
						
							tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array, 'update', "subscription_id = '" . (int)$subscription_id . "'");
							
							tep_db_query("delete from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '". (int)$subscription_id . "'");
				        }


						# create loop here to insert rows for multiple categories
						$selected_subscription_catids = $HTTP_POST_VARS['subscription_categories_ids'];
						if ($selected_subscription_catids)
						{
							foreach ($selected_subscription_catids as $current_subscription_category_id)
							{	
								tep_db_query("insert into " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " (subscription_id, subscription_categories_id) values ('" . $subscription_id . "', '" . $current_subscription_category_id . "')");
								$sucPath=$current_subscription_category_id;
							}
						}

						$languages = tep_get_languages();
						for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
							$language_id = $languages[$i]['id'];

							$sql_data_array = array('subscription_name' => tep_db_prepare_input($HTTP_POST_VARS['subscription_name'][$language_id]),
													'subscription_description' => tep_db_prepare_input($HTTP_POST_VARS['subscription_description'][$language_id]),
													'subscription_url' => tep_db_prepare_input($HTTP_POST_VARS['subscription_url'][$language_id]));
							if ($action == 'insert_subscription') {
								$insert_sql_data = array(	'subscription_id' => $subscription_id,
															'language_id' => $language_id);
							
								$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
							
								tep_db_perform(TABLE_SUBSCRIPTIONS_DESCRIPTION, $sql_data_array);
							} elseif ($action == 'update_subscription') {
								tep_db_perform(TABLE_SUBSCRIPTIONS_DESCRIPTION, $sql_data_array, 'update', "subscription_id = '" . (int)$subscription_id . "' and language_id = '" . (int)$language_id . "'");
							}
						}
				
				}				
				tep_redirect(tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'top=1&mPath=5'));
        		break;
			case 'delete_subscription_confirm':
				if (isset($HTTP_POST_VARS['subscription_id']) && isset($HTTP_POST_VARS['subscription_categories']) && is_array($HTTP_POST_VARS['subscription_categories'])) {
					$subscription_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_id']);
					$subscription_categories = $HTTP_POST_VARS['subscription_categories'];
					for ($i=0, $n=sizeof($subscription_categories); $i<$n; $i++) {
						tep_db_query("delete from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "' and subscription_categories_id = '" . (int)$subscription_categories[$i] . "'");
					}
			
					$subscription_categories_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "'");
					$subscription_categories = tep_db_fetch_array($subscription_categories_query);
			
					if ($subscription_categories['total'] == '0') {
						tep_remove_subscription($subscription_id);
					}
				}

	
				tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath));
				break;
			case 'move_subscription_confirm':
				$subscription_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_id']);
				$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_subscription_category_id']);
				if ($new_parent_id!=0)
				{
					$duplicate_check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "' and subscription_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_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " set subscription_categories_id = '" . (int)$new_parent_id . "' where subscription_id = '" . (int)$subscription_id . "' and subscription_categories_id = '" . (int)$current_subscription_category_id . "'");
					tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $new_parent_id . '&suID=' . $subscription_id));
				}
        		break;
      		case 'copy_to_confirm':
				if (isset($HTTP_POST_VARS['subscription_id']) && isset($HTTP_POST_VARS['subscription_categories_id'])) {
					$subscription_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_id']); 
					$subscription_categories_id = tep_db_prepare_input($HTTP_POST_VARS['subscription_categories_id']);
				if ($HTTP_POST_VARS['copy_as'] == 'link') {
					if ($subscription_categories_id != $current_subscription_category_id) {
						$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "' and subscription_categories_id = '" . (int)$subscription_categories_id . "'");
						$check = tep_db_fetch_array($check_query);
						if ($check['total'] < '1') {
							tep_db_query("insert into " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " (subscription_id, subscription_categories_id) values ('" . (int)$subscription_id . "', '" . (int)$subscription_categories_id . "')");
						}
					} else {
						$messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_SUBSCRIPTION_CATEGORY, 'error');
					}
				} elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
					$subscription_query = tep_db_query("SELECT subscription_image, subscription_date_available, subscription_status, subscription_tax_class_id,subscription_costs,subscription_type,"
												. "subscription_group,subscription_conditions,subscription_pending_period,subscription_renewal_start,subscription_renewal_end,"
												. "subscription_packing_slip,subscription_free_trial,subscription_free_days,emarketing_on_renewal,wallet_payment,periodic_payment,"
												. "periodic_days,periodic_type,deliveries,deliveries_name,deliveries_perday,"
												. "subscription_start_date,subscription_finish_date,subscription_period,subscription_date_type,subscription_latest_start_date  "
												. " from " . TABLE_SUBSCRIPTIONS . " where subscription_id = '" . (int)$subscription_id . "'");
					$subscription = tep_db_fetch_array($subscription_query);
					
					tep_db_query("insert into " . TABLE_SUBSCRIPTIONS . " (subscription_image, subscription_date_added,subscription_date_available, subscription_status, subscription_tax_class_id,subscription_costs,subscription_type,"
								. "subscription_group,subscription_conditions,subscription_pending_period,subscription_renewal_start,subscription_renewal_end,"
								. "subscription_packing_slip,subscription_free_trial,subscription_free_days,emarketing_on_renewal,wallet_payment,periodic_payment,periodic_days,periodic_type,deliveries,deliveries_name,deliveries_perday,"
								. "subscription_start_date,subscription_finish_date,subscription_period,subscription_date_type,subscription_latest_start_date "
								. " ) values ('" . tep_db_input($subscription['subscription_image']) . "',  now(), '" . tep_db_input($subscription['subscription_date_available']) . "', '" . tep_db_input($subscription['subscription_status'])
								. "', '" . tep_db_input($subscription['subscription_tax_class_id']) . "', '" . tep_db_input($subscription['subscription_costs'])
								. "', '" . tep_db_input($subscription['subscription_type']) . "', '" . tep_db_input($subscription['subscription_group'])
								. "', '" . tep_db_input($subscription['subscription_conditions']) . "', '" . tep_db_input($subscription['subscription_pending_period']) . "', '" . tep_db_input($subscription['subscription_renewal_start'])
								. "', '" . tep_db_input($subscription['subscription_renewal_end'])	. "', '" . tep_db_input($subscription['subscription_packing_slip']) 
								. "', '" . tep_db_input($subscription['subscription_free_trial'])	. "', '" . tep_db_input($subscription['subscription_free_days']) 
								. "', '" . tep_db_input($subscription['emarketing_on_renewal'])	. "','" . tep_db_input($subscription['wallet_payment'])
								. "','" . tep_db_input($subscription['periodic_payment']) . "','" . tep_db_input($subscription['periodic_days']) 
								. "','" . tep_db_input($subscription['periodic_type']) . "','" .tep_db_input($subscription['deliveries'])
								. "','" . tep_db_input($subscription['deliveries_name']) . "','". tep_db_input($subscription['deliveries_perday'])
								."','" . tep_db_input($subscription['subscription_start_date']) . "','" . tep_db_input($subscription['subscription_finish_date'])
								. "','" . tep_db_input($subscription['subscription_period']) . "','" . tep_db_input($subscription['subscription_date_type'])
								. "','" . tep_db_input($subscription['subscription_latest_start_date']) . "')");
					$dup_subscription_id = tep_db_insert_id();

					$description_query = tep_db_query("SELECT language_id, subscription_name, subscription_description,subscription_url from " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " where subscription_id = '" . (int)$subscription_id . "'");
					while ($description = tep_db_fetch_array($description_query)) {
						tep_db_query("insert into " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " (subscription_id, language_id, subscription_name, subscription_description, subscription_url, subscription_viewed) values ('" . 
									(int)$dup_subscription_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['subscription_name']) . "', '" . tep_db_input($description['subscription_description']) . "', '" . 
									tep_db_input($description['subscription_url']) . "', '0')");
					}
					tep_db_query("insert into " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " (subscription_id, subscription_categories_id) values ('" . (int)$dup_subscription_id . "', '" . (int)$subscription_categories_id . "')");
					
					// copy subscription messages
					if (isset($HTTP_POST_VARS["copy_subscription"])){
						$message_query=tep_db_query("SELECT message_send,message_send1,message_subject,message_text,message_format,subscription_id,message_type,message_reply_to from " . 
													TABLE_SUBSCRIPTION_MESSAGES . " su where subscription_id='" . (int)$subscription_id ."'"
													);
						while($message_result=tep_db_fetch_array($message_query)){
							$message_result["subscription_id"]=$dup_subscription_id;
							tep_db_perform(TABLE_SUBSCRIPTION_MESSAGES,$message_result);
						}
						
					}
			}
		}

			tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $subscription_categories_id . '&suID=' . $subscription_id));
			break;
		case 'new_subscription_preview':
				// copy image only if modified
			$subscription_image = new upload('subscription_image');
			$subscription_image->set_destination(DIR_FS_CATALOG_IMAGES);
			if ($subscription_image->parse() && $subscription_image->save()) {
				$subscription_image_name = $subscription_image->filename;
			} else {
				$subscription_image_name = (isset($HTTP_POST_VARS['subscription_previous_image']) ? $HTTP_POST_VARS['subscription_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');
	}

	$go_back_to=$REQUEST_URI;
	
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/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 include('includes/date_format_js.php');?>
<script language="javascript">
	var category_list = new Array();
	category_list[0]= 'panel_Categories';
	category_list[1]= 'panel_General';
	category_list[2]= 'panel_Fees';
	category_list[3]= 'panel_Conditions';
	
	function do_subscription_type(){ 
		var frm=document.forms["new_subscription"];
		var subscription_type=frm.subscription_type.options[frm.subscription_type.selectedIndex].value;
		var div_ids_deliveries=document.getElementById("box_deliveries");
		var div_ids_perday=document.getElementById("box_perday");
		if(subscription_type=='C'){
			div_ids_deliveries.style.display=div_ids_perday.style.display="";
		}else if(subscription_type=='S'){	
			div_ids_deliveries.style.display="";
			div_ids_perday.style.display="none"	
		}else{
			div_ids_deliveries.style.display=div_ids_perday.style.display="none";
		}
	}
</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" onLoad="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- 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_subscription_category_ACD' || $HTTP_GET_VARS['action'] == 'edit_subscription_category_ACD') {
				if ( ($HTTP_GET_VARS['sucID']) && (!$HTTP_POST_VARS) ) {
					$subscription_categories_query = tep_db_query("SELECT suc.subscription_categories_id, sucd.subscription_categories_name, sucd.subscription_categories_heading_title, sucd.subscription_categories_description, suc.subscription_categories_image, suc.parent_id, suc.sort_order, suc.date_added, suc.last_modified from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id = sucd.subscription_categories_id and suc.subscription_categories_id = '" . (int)$HTTP_GET_VARS['sucID'] . "' and sucd.language_id = '" . (int)$languages_id . "' order by suc.sort_order, sucd.subscription_categories_name");
					$subscription_category = tep_db_fetch_array($subscription_categories_query);
			
					$sucInfo = new objectInfo($subscription_category);
				} elseif ($HTTP_POST_VARS) {
					$sucInfo = new objectInfo($HTTP_POST_VARS);
					$subscription_categories_name = $HTTP_POST_VARS['subscription_categories_name'];
					$subscription_categories_heading_title = $HTTP_POST_VARS['subscription_categories_heading_title'];
					$subscription_categories_description = $HTTP_POST_VARS['subscription_categories_description'];
					$subscription_categories_url = $HTTP_POST_VARS['subscription_categories_url'];
				} else {
					$sucInfo = new objectInfo(array());
				}
				$languages = tep_get_languages();
				$text_new_or_edit = ($HTTP_GET_VARS['action']=='new_subscription_category_ACD') ? TEXT_INFO_HEADING_NEW_SUBSCRIPTION_CATEGORY : TEXT_INFO_HEADING_EDIT_SUBSCRIPTION_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_subscription_category_path($current_subscription_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_subscription_category', FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $HTTP_GET_VARS['sucID'] . '&action=new_subscription_category_preview', 'post', ' onSubmit="javascript:return validate_image()" enctype="multipart/form-data"'); ?>
				<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_SUBSCRIPTION_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('subscription_categories_name[' . $languages[$i]['id'] . ']', (tep_not_null($subscription_categories_name[$languages[$i]['id']]) ? stripslashes($subscription_categories_name[$languages[$i]['id']]) : tep_get_subscription_category_name($sucInfo->subscription_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_SUBSCRIPTION_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('subscription_categories_heading_title[' . $languages[$i]['id'] . ']', (tep_not_null($subscription_categories_heading_title[$languages[$i]['id']]) ? stripslashes($subscription_categories_heading_title[$languages[$i]['id']]) : tep_get_subscription_category_title($sucInfo->subscription_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_SUBSCRIPTION_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('subscription_categories_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (tep_not_null($subscription_categories_description[$languages[$i]['id']]) ? stripslashes($subscription_categories_description[$languages[$i]['id']]) : tep_get_subscription_category_description($sucInfo->subscription_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_SUBSCRIPTION_CATEGORIES_IMAGE; ?></td>
					<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('subscription_categories_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $sucInfo->subscription_categories_image . tep_draw_hidden_field('subscription_categories_previous_image', $sucInfo->subscription_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_SUBSCRIPTION_CATEGORIES_SORT_ORDER; ?></td>
					<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sort_order', $sucInfo->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('subscription_categories_date_added', (($sucInfo->date_added) ? $sucInfo->date_added : getServerDate())) . tep_draw_hidden_field('parent_id', $sucInfo->parent_id) . tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . (isset($HTTP_GET_VARS['sucID'])?'&sucID=' . $HTTP_GET_VARS['sucID']:'')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
		</tr>
	<?php
			echo "</form>";
	} elseif ($HTTP_GET_VARS['action'] == 'new_subscription_ACD' || $HTTP_GET_VARS['action'] == 'edit_subscription_ACD'){
	
				$languages = tep_get_languages();
				$parameters = array('subscription_name' => '',
									'subscription_description' => '',
									'subscription_url' => '',
									'subscription_id' => '',
									'subscription_image' => '',
									'subscription_type'=>'T',
									'subscription_costs' => '',
									'subscription_date_added' => '',
									'subscription_last_modified' => '',
									'subscription_date_available' => '',
									'subscription_pending_period'=>'',
									'subscription_renewal_start'=>'0',
									'subscription_renewal_end'=>'0',
									//'subscription_period'=>"10",
									'subscription_group'=>"",
									'subscription_status' => '1',
									'subscription_free_trial'=>'N',
									'subscription_free_days'=>'1',
									'subscription_packing_slip'=>'',
									'emarketing_on_renewal'=>'S',
									'subscription_conditions'=>'',
									'wallet_payment'=>'Y',
									'periodic_payment'=>'N',
									'periodic_days'=>0,
									'periodic_type'=>'A',
									'deliveries'=>1,
									'deliveries_name'=>'Deliveries',
									'deliveries_perday'=>1
									);
		
			$suInfo = new objectInfo($parameters);
			//require(DIR_WS_CLASSES . 'payment.php');
			//$payment_modules = new payment;
		
			if (isset($HTTP_GET_VARS['suID']) && (!$HTTP_POST_VARS)) {
			  $subscription_query = tep_db_query("SELECT sud.subscription_name, sud.subscription_description, sud.subscription_url, su.subscription_id, su.subscription_image, " .
										   "su.subscription_date_added,su.emarketing_on_renewal, su.subscription_last_modified, date_format(su.subscription_date_available, '%Y-%m-%d') " .
										   "as subscription_date_available, su.subscription_status, su.subscription_tax_class_id, su.subscription_costs, " .
										   "su.subscription_pending_period,su.subscription_renewal_start,su.subscription_renewal_end,su.subscription_free_trial,su.subscription_free_days, " .
										   "su.subscription_type,su.subscription_group,su.subscription_conditions,su.subscription_packing_slip, ".
										   "su.wallet_payment,su.periodic_payment,su.periodic_days,su.periodic_type,su.deliveries,su.deliveries_name,su.deliveries_perday,su.subscription_date_type, " .
										   "su.subscription_start_date,su.subscription_finish_date,su.subscription_latest_start_date,su.subscription_period from " . 
											TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where su.subscription_id=sud.subscription_id " .
										   " and su.subscription_id = '" . (int)$HTTP_GET_VARS['suID'] . "' and sud.language_id = '" . (int)$languages_id . "'");
			  $subscription = tep_db_fetch_array($subscription_query);
		
			  $suInfo=new objectInfo($subscription);
			} elseif ($HTTP_POST_VARS) {
			  $suInfo=new objectInfo($HTTP_POST_VARS);
			  $subscription_name = $HTTP_POST_VARS['subscription_name'];
			  $subscription_description = $HTTP_POST_VARS['subscription_description'];
			  $subscription_url = $HTTP_POST_VARS['subscription_url'];
			} 
			#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']);
			} 
			
			$status_array=array(array('id'=>1,'text'=>TEXT_HIDE_NONE),
								array('id'=>0,'text'=>TEXT_HIDE_ALWAYS));
								
			if (!isset($suInfo->subscription_status)) $suInfo->subscription_status = '1';
				$form_action = ($HTTP_GET_VARS['suID']) ? 'update_subscription' : 'insert_subscription';
		
			$merge_fields=array(array("id"=>"NA","text"=>DELI_NA),
								array("id"=>"CT","text"=>DELI_CT),
								array("id"=>"CC","text"=>DELI_CC),
								array("id"=>"CE","text"=>DELI_CE),
								array("id"=>"CP","text"=>DELI_CP),
								array("id"=>"CU","text"=>DELI_CU)
								);
								
		# get selected categories
		$subscription_categories_query_selected = tep_db_query("SELECT subscription_categories_id from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$HTTP_GET_VARS['suID'] . "'");
		$subscription_categories_array_selected = array(array('id' => ''));
		while ($subscription_categories = tep_db_fetch_array($subscription_categories_query_selected)) {
		  $subscription_categories_array_selected[] = array('id' => $subscription_categories['subscription_categories_id']);
		}
		
		$subscription_categories_array = array(array('id' => '', 'text' => TEXT_NONE));

		$language_id = 1;
		$subscription_categories_array = tep_get_subscription_category_tree(); 
		// get selected groups
		$subscription_groups_query = tep_db_query("SELECT subscription_group_name from " . TABLE_SUBSCRIPTIONS_GROUP);
		$subscription_groups_array = array(array('id' => '','text'=>''));
		while ($subscription_groups = tep_db_fetch_array($subscription_groups_query)) {

		  $subscription_groups_array[] = array('id' => $subscription_groups['subscription_group_name'],'text'=>$subscription_groups['subscription_group_name']);
		}
		
		//get wallet periodic type
		$wallet_periodic_fields=array(array("id"=>"A","text"=>TEXT_AFTER_SUBSCRIPTION),
								array("id"=>"B","text"=>TEXT_BEFORE_SUBSCRIPTION)
								)

	?>
		<script language="javascript">
		var lang=new Array();  
		var tax_rates = new Array();
		<?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 ValidateForm(){
		
		 var error_result;
		 var count=0;
		 error_result="";
		 count=0;
		 
		// alert ('hi');
		  
		var image_types=Array(".png",".jpg",".jpeg",".gif");
		if (document.new_subscription.elements["subscription_image"].value!="" && !check_mime_type(document.new_subscription.elements["subscription_image"],image_types)){
			error_result+="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
		}
		 var frm_subscription_type=document.new_subscription.subscription_type.options[document.new_subscription.subscription_type.selectedIndex].value;
		 if (document.new_subscription.elements["subscription_name["+lang[0]+"]"]){
		  for (icnt=0;icnt<lang.length;icnt++){
			if (document.new_subscription.elements["subscription_name["+lang[icnt]+"]"].value==""){
			 alert (document.new_subscription.elements["subscription_name["+lang[icnt]+"]"].value);
			  error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_NAME); ?>";break;}
		  }
		 } else if (document.new_subscription.subscription_name.value==""){
		
		 	  error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_NAME); ?>";
		 }
		
		 if (error_result==''){
		   if (document.new_subscription.subscription_categories_ids.selectedIndex<0){
			error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_CATEGORY); ?>";
			}else if(document.new_subscription.subscription_pending_period.value=="")
		{
			error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_PENDING_PERIED_EMPTY); ?>";
		}else if(isNaN(parseInt(document.new_subscription.subscription_pending_period.value))){
			error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_PENDING_PERIED_NUMBER); ?>";
		}else if(document.new_subscription.subscription_renewal_start.value==""){
			error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_START_EMPTY); ?>";
		}else if(isNaN(parseInt(document.new_subscription.subscription_renewal_start.value)))
		{
			error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_START_NUMBER); ?>";
		}else if(document.new_subscription.subscription_renewal_end.value=="")
		{
			error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_END_EMPTY); ?>";
		}else if(isNaN(parseInt(document.new_subscription.subscription_renewal_end.value))){
			error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_END_NUMBER); ?>";
		}else if(frm_subscription_type=='C' || frm_subscription_type=='S') {
			var txt_deliveries=document.new_subscription.txt_deliveries.value;
			var txt_deliveries_name = document.new_subscription.txt_deliveries_name.value;
		   var txt_deliveries_perday=document.new_subscription.txt_perday.value; 
			if(txt_deliveries<=0 || txt_deliveries=="" || isNaN(txt_deliveries)){
				error_result+="<?php echo ERR_DELIVERIES_COUNT;?>\n";	
			}
			if(txt_deliveries_name == ""){
				error_result+="<?php echo ERR_DELIVERIES_NAME;?>\n";
			}
			if(frm_subscription_type=='C' && (txt_deliveries_perday<=0 || txt_deliveries_perday=="" || isNaN(txt_deliveries_perday))){
				error_result+="<?php echo ERR_DELIVERIES_PERDAYS;?>";	
			}
		}
		}
		/*var fixed_type = document.new_subscription.subscription_date_type[0];
		var flexible_type = document.new_subscription.subscription_date_type[1];
		var predefined_type = document.new_subscription.subscription_date_type[2];
		if(fixed_type.checked==true || flexible_type.checked==true || predefined_type.checked==true){
			var error_result = "";
			var currend_date = document.new_subscription.currend_date.value;
			
			if(document.new_subscription.subscription_start_date.value==""){
				error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
				//document.new_subscription.subscription_start_date.value = currend_date;
			} else if(document.new_subscription.subscription_start_date.value!=""){
				var date_error = true;
				if((document.new_subscription.subscription_start_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_subscription.subscription_start_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
					//document.new_subscription.subscription_start_date.value = currend_date;
				}
			}
			
			var start_date_time = 0;
			var finish_date_time = 0;
			if(document.new_subscription.subscription_start_date.value != ""){
				var date_error = true;
				if((document.new_subscription.subscription_finish_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_subscription.subscription_finish_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					error_result+="* <?php echo ERR_SUBSCRIPTION_FINISH_DATE;?>\n";
					//document.new_subscription.subscription_finish_date.value = document.new_subscription.subscription_start_date.value;
				}else{
					 start_date_time = date_format(document.new_subscription.subscription_start_date.value,'','',true).getTime();
					 finish_date_time = date_format(document.new_subscription.subscription_finish_date.value,'','',true).getTime();
				}
			}
			if(start_date_time>finish_date_time){
				error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_BEGIN_DATE;?>\n";
				//document.new_subscription.subscription_finish_date.value=document.new_subscription.subscription_start_date.value;
			}
			if(document.new_subscription.subscription_finish_date.value==""){
				error_result+="* <?php echo ERR_SUBSCRIPTION_FINISH_DATE;?>\n";
				//document.new_subscription.subscription_finish_date.value = document.new_subscription.subscription_start_date.value;
			} 
			
			var period = document.new_subscription.subscription_period.value;
			if(isNaN(parseInt(period))){
				error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_ATTENDANCE_PERIOD;?>";
				//document.new_subscription.subscription_period.value=1;
			}		
			if(period < 0){
				error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_GREATER_ATTENDANCE_PERIOD;?>";
				//document.new_subscription.subscription_period.value=1;
			}
			
			if(flexible_type.checked==true || predefined_type.checked==true){
				if(document.new_subscription.subscription_latest_start_date.value==""){
					error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE;?>\n";
					//document.new_subscription.subscription_latest_start_date.value = document.new_subscription.subscription_start_date.value;
				} else if(document.new_subscription.subscription_latest_start_date.value!=""){
					var date_error = true;
					if((document.new_subscription.subscription_latest_start_date.value).indexOf("-")!=-1){
						date_error = isValidDate(date_format(document.new_subscription.subscription_latest_start_date.value,'','Y-m-d'));
					} else {
						date_error = false;
					}
					if(!(date_error)){
						error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE;?>\n";
						//document.new_subscription.subscription_latest_start_date.value = document.new_subscription.subscription_start_date.value;
					} else{
						 finish_date_time = date_format(document.new_subscription.subscription_finish_date.value,'','',true).getTime();
						 latest_start_date_time = date_format(document.new_subscription.subscription_latest_start_date.value,'','',true).getTime();
					}
					if(latest_start_date_time>finish_date_time){
						error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE_EXCEED_FINISH_DATE;?>\n";
						//document.new_subscription.subscription_latest_start_date.value=document.new_subscription.subscription_start_date.value;
					}
					if(latest_start_date_time<start_date_time){
						error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_LATEST_START_DATE;?>\n";
						//document.new_subscription.subscription_latest_start_date.value=document.new_subscription.subscription_start_date.value;
					}
				}
			}*/
			/*	if(document.new_subscription.subscription_start.checked){
			if(document.new_subscription.subscription_start_date.value==""){
				error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
			} else if(document.new_subscription.subscription_start_date.value!=""){
				var date_error = true;
				if((document.new_subscription.subscription_start_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_subscription.subscription_start_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
				}
			}
		}
		if(document.new_subscription.subscription_begins.checked){
			var start_date_time = 0;
			var begin_date_time = 0;
			if(document.new_subscription.subscription_start_date.value != ""){
				var date_error = true;
				if((document.new_subscription.subscription_begins_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_subscription.subscription_begins_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_DATE;?>\n";
				}else{
					 start_date_time = date_format(document.new_subscription.subscription_start_date.value,'','',true).getTime();
					 begin_date_time = date_format(document.new_subscription.subscription_begins_date.value,'','',true).getTime();
				}
			}
			if(start_date_time>begin_date_time){
				error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_BEGIN_DATE;?>\n";
			}
			if(document.new_subscription.subscription_begins_date.value==""){
				error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_DATE;?>\n";
			} 
		}
		if(document.new_subscription.subscription_attendance_period.checked){
			var period = document.new_subscription.subscription_begins_attendance_period.value;
			if(isNaN(parseInt(period))){
				error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_ATTENDANCE_PERIOD;?>";
			}		
			if(period < 0){
				error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_GREATER_ATTENDANCE_PERIOD;?>";
			}
		} */
		
		 if (error_result!=""){
		   alert(error_result);
		   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_subscription"].subscription_tax_class_id.selectedIndex;
		  var parameterVal = document.forms["new_subscription"].subscription_tax_class_id[selected_value].value;
		
		  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
			return tax_rates[parameterVal];
		  } else {
			return 0;
		  }
		}
		
		 function set_action(type) {
		 	var frm=document.new_subscription;
			if (type==1 && frm.wallet_payment.checked==true) {
				frm.periodic_payment.checked=false;
			} else if (type==2 && frm.periodic_payment.checked==true) {
				frm.wallet_payment.checked=false;
			}
			frm.periodic_type.disabled=!frm.periodic_payment.checked;
			frm.periodic_days.disabled=!frm.periodic_payment.checked;
		}
		function updateGross() {
		  var taxRate = getTaxRate();
		  var grossValue = document.forms["new_subscription"].subscription_costs_net.value;
		
		  if (taxRate > 0) {
			grossValue = grossValue * ((taxRate / 100) + 1);
		  }
		
		  document.forms["new_subscription"].subscription_costs_gross.value = doRound(grossValue, 4);
		}
		
		function updateNet() {
		  var taxRate = getTaxRate();
		  var netValue = document.forms["new_subscription"].subscription_costs_gross.value;
		
		  if (taxRate > 0) {
			netValue = netValue / ((taxRate / 100) + 1);
		  }
		  document.forms["new_subscription"].subscription_costs_net.value = doRound(netValue, 4);
		}
		function AddField(){
		 var select_field;
		 var select_id;
		 if (document.new_subscription.merge_fields.selectedIndex<=-1) return;
		 select_id=document.new_subscription.merge_fields.options[document.new_subscription.merge_fields.selectedIndex].value;
		 if (select_id.length>3) return;
		 select_field="%%" + document.new_subscription.merge_fields.options[document.new_subscription.merge_fields.selectedIndex].text + "%%";
			textArea=document.new_subscription.message_text;
			textArea.focus();
			if (textArea.selection){
				sRange  = document.selection.createRange();
				var sText   = sRange.text;
				sRange.text = select_field;
			} else if (textArea.selectionStart || textArea.selectionStart == "0") {
				var startPos = textArea.selectionStart;
				var endPos = textArea.selectionEnd;
				textArea.value = textArea.value.substring(0, startPos)
						+ select_field + textArea.value.substring(endPos, textArea.value.length);
			} else {
				textArea.value += select_field;
			}		
		}
		
	var old_start_date = '';
	var old_finish_date = '';
	var old_latest_start_date = '';
	var old_forward_period = 1;
	//setInterval("check_input()",10000);
	function do_subscription_date_type(){
		if(document.new_subscription.subscription_date_type[0].checked==true){
			old_finish_date = 0;
			document.getElementById("fixed_date").style.display="none";
			check_input(false);
		} else if(document.new_subscription.subscription_date_type[1].checked==true || document.new_subscription.subscription_date_type[2].checked==true){
			old_finish_date = 0;
			document.getElementById("fixed_date").style.display="";
			check_input(false);
		}
	}

	function check_input(display_alert){
		var fixed_type = document.new_subscription.subscription_date_type[0];
		var flexible_type = document.new_subscription.subscription_date_type[1];
		var predefined_type = document.new_subscription.subscription_date_type[2];
		
		if (flexible_type) document.new_subscription.subscription_date_type[1];
		if(fixed_type.checked==true || flexible_type.checked==true || predefined_type.checked==true){
			var error_result = "";
			var currend_date = document.new_subscription.currend_date.value;
			if(document.new_subscription.subscription_start_date.value==""){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
				document.new_subscription.subscription_start_date.value = currend_date;
			} else if(document.new_subscription.subscription_start_date.value!=""){
				var date_error = true;
				if((document.new_subscription.subscription_start_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_subscription.subscription_start_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
					document.new_subscription.subscription_start_date.value = currend_date;
				}
			}
			
			var start_date_time = 0;
			var finish_date_time = 0;
			var latest_start_date_time = 0;
			if(document.new_subscription.subscription_start_date.value != ""){
				var date_error = true;
				if((document.new_subscription.subscription_finish_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_subscription.subscription_finish_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_FINISH_DATE;?>\n";
					document.new_subscription.subscription_finish_date.value = document.new_subscription.subscription_start_date.value;
				}else{
					 start_date_time = date_format(document.new_subscription.subscription_start_date.value,'','',true).getTime();
					 finish_date_time = date_format(document.new_subscription.subscription_finish_date.value,'','',true).getTime();
				}
			}
			if(start_date_time>finish_date_time){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_BEGIN_DATE;?>\n";
				document.new_subscription.subscription_finish_date.value=document.new_subscription.subscription_start_date.value;
			}
			if(document.new_subscription.subscription_finish_date.value==""){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_FINISH_DATE;?>\n";
				document.new_subscription.subscription_finish_date.value = document.new_subscription.subscription_start_date.value;
			} 
			
			var period = document.new_subscription.subscription_period.value;
			if(isNaN(parseInt(period))){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_ATTENDANCE_PERIOD;?>";
				document.new_subscription.subscription_period.value=1;
			}		
			if(period < 0){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_GREATER_ATTENDANCE_PERIOD;?>";
				document.new_subscription.subscription_period.value=1;
			}
			
			if(flexible_type.checked==true || predefined_type.checked==true){
				if(document.new_subscription.subscription_latest_start_date.value==""){
					if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE;?>\n";
					document.new_subscription.subscription_latest_start_date.value = document.new_subscription.subscription_start_date.value;
				} else if(document.new_subscription.subscription_latest_start_date.value!=""){
					var date_error = true;
					if((document.new_subscription.subscription_latest_start_date.value).indexOf("-")!=-1){
						date_error = isValidDate(date_format(document.new_subscription.subscription_latest_start_date.value,'','Y-m-d'));
					} else {
						date_error = false;
					}
					if(!(date_error)){
						if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE;?>\n";
						document.new_subscription.subscription_latest_start_date.value = document.new_subscription.subscription_start_date.value;
					} else{
						 finish_date_time = date_format(document.new_subscription.subscription_finish_date.value,'','',true).getTime();
						 latest_start_date_time = date_format(document.new_subscription.subscription_latest_start_date.value,'','',true).getTime();
					}
					if(latest_start_date_time>finish_date_time){
						if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE_EXCEED_FINISH_DATE;?>\n";
						document.new_subscription.subscription_latest_start_date.value=document.new_subscription.subscription_start_date.value;
					}
					if(latest_start_date_time<start_date_time){
					//alert (document.new_subscription.subscription_latest_start_date.value);
						var check_start_date = date_format(document.new_subscription.subscription_start_date.value,'','d-m-Y');
						if(old_start_date == check_start_date)
							if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_LATEST_START_DATE;?>\n";
						document.new_subscription.subscription_latest_start_date.value=document.new_subscription.subscription_start_date.value;
					}
				}
			}
			
			if (error_result!=""){
			   alert(error_result);
			   check_input(true);
			   return false;
			}
			var latest_start_date = '';
			if(document.new_subscription.subscription_latest_start_date.value ==""){
				document.new_subscription.subscription_latest_start_date.value="00:00:0000";
				latest_start_date = date_format(document.new_subscription.subscription_latest_start_date.value,'d-m-Y','d-m-Y');	
			}
			var start_date = date_format(document.new_subscription.subscription_start_date.value,'','d-m-Y');
			var finish_date = date_format(document.new_subscription.subscription_finish_date.value,'','d-m-Y');
			latest_start_date = date_format(document.new_subscription.subscription_latest_start_date.value,'','d-m-Y');
			var forward_period = document.new_subscription.subscription_period.value;
			if(old_start_date != start_date || old_finish_date != finish_date || old_latest_start_date != latest_start_date || old_forward_period != forward_period){
				var date_array = Array(start_date,finish_date,latest_start_date);
				var total_days = Array(0,0,0);
				for(i=0;i<date_array.length;i++){
					var split_date = date_array[i].split("-");
					var month_array = Array();
					var leep_years = 0;
					leep_years = parseInt(split_date[2]/4);
					total_days[i] += leep_years*366;
					var non_leep_years = 0;
					non_leep_years = parseInt(split_date[2]-(split_date[2]/4));
					total_days[i] += non_leep_years*365;
					var is_leep_year = ((String)(split_date[2]/4)).indexOf(".");
					if(is_leep_year!=-1){
						month_days = Array(31,28,31,30,31,30,31,31,30,31,30,31);
					} else {
						month_days = Array(31,29,31,30,31,30,31,31,30,31,30,31);
						total_days[i] -= 366;
					}
					for(j=0;j<month_days.length;j++){
						if((j+1)<split_date[1]){
							total_days[i] += month_days[j];
						}
					}
					total_days[i] += new Number(split_date[0]);
				}
				if(fixed_type.checked == true){
					if(old_finish_date != finish_date || old_start_date != start_date){
						document.new_subscription.subscription_period.value = total_days[1]-total_days[0]+1;
						old_forward_period = total_days[1]-total_days[0]+1;
						old_finish_date = finish_date;
					} else if(old_forward_period != forward_period){
						var s_date = new Date();
						var split_date = document.new_subscription.subscription_start_date.value.split("-");
						s_date.setDate(split_date[0]);s_date.setMonth(split_date[1]-1);s_date.setYear(split_date[2]);
						s_date.setMinutes(0);s_date.setSeconds(0);s_date.setHours(0);s_date.setMilliseconds(0);
						var to_forward_period = 1;
						if(forward_period != 0)to_forward_period = forward_period;
						var day = DateAdd('d',to_forward_period-1,s_date).getDate();
						var month = DateAdd('d',to_forward_period-1,s_date).getMonth();
						var year = DateAdd('d',to_forward_period-1,s_date).getYear();
						month +=1;
						//day -=1;if(day!=1)
						if(year<1000)year +=1900;
						if(day<10)day = 0+""+day;
						if(month<10)month = 0+""+month;
						document.new_subscription.subscription_finish_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_finish_date = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_forward_period = forward_period;
					}
					var check_start_date_time = date_format(document.new_subscription.subscription_start_date.value,'','',true).getTime();
					var check_finish_date_time = date_format(document.new_subscription.subscription_finish_date.value,'','',true).getTime();
					if(check_start_date_time>check_finish_date_time){
						//alert("* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_BEGIN_DATE;?>\n");
						document.new_subscription.subscription_finish_date.value=document.new_subscription.subscription_start_date.value;
						old_finish_date = start_date;
						return false;
					}
				}
				if(flexible_type.checked == true || predefined_type.checked == true){
					if(old_finish_date != finish_date || old_start_date != start_date || old_latest_start_date != latest_start_date){
						if(old_latest_start_date != latest_start_date || old_finish_date != finish_date){
							document.new_subscription.subscription_period.value = total_days[1]-total_days[2]+1;
							old_forward_period = total_days[1]-total_days[2]+1;
							old_finish_date = finish_date;
							old_latest_start_date = latest_start_date;
						}
						if(old_start_date != start_date || old_latest_start_date != start_date){
							if(total_days[0]>total_days[2]){
								document.new_subscription.subscription_latest_start_date.value = start_date;
								old_latest_start_date = latest_start_date;
							}
						}
					} else if(old_forward_period != forward_period){
						var s_date = new Date();
						var split_date = document.new_subscription.subscription_finish_date.value.split("-");
						s_date.setDate(split_date[0]);s_date.setMonth(split_date[1]-1);s_date.setYear(split_date[2]);
						s_date.setMinutes(0);s_date.setSeconds(0);s_date.setHours(0);s_date.setMilliseconds(0);
						var to_forward_period = 1;
						if(forward_period != 0)to_forward_period = forward_period;
						var day = DateSub('d',to_forward_period-1,s_date).getDate();
						var month = DateSub('d',to_forward_period-1,s_date).getMonth();
						var year = DateSub('d',to_forward_period-1,s_date).getYear();
						month +=1;
						//day +=1;if(day!=1)
						if(year<1000)year +=1900;
						if(day<10)day = 0+""+day;
						if(month<10)month = 0+""+month;
						document.new_subscription.subscription_latest_start_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_latest_start_date = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_forward_period = forward_period;
						old_finish_date = finish_date;
					}
					var check_start_date_time = date_format(document.new_subscription.subscription_start_date.value,'','',true).getTime();
					var check_finish_date_time = date_format(document.new_subscription.subscription_finish_date.value,'','',true).getTime();
					var check_latest_start_date_time = date_format(document.new_subscription.subscription_latest_start_date.value,'','',true).getTime();
						var s_date = new Date();
						var split_date = document.new_subscription.subscription_start_date.value.split("-");
						s_date.setDate(split_date[0]);s_date.setMonth(split_date[1]-1);s_date.setYear(split_date[2]);
						s_date.setMinutes(0);s_date.setSeconds(0);s_date.setHours(0);s_date.setMilliseconds(0);
						var to_forward_period = 1;
						if(forward_period != 0)to_forward_period = forward_period;
						var day = DateAdd('d',to_forward_period-1,s_date).getDate();
						var month = DateAdd('d',to_forward_period-1,s_date).getMonth();
						var year = DateAdd('d',to_forward_period-1,s_date).getYear();
						month +=1;
						//day -=1;if(day!=1)
						if(year<1000)year +=1900;
						if(day<10)day = 0+""+day;
						if(month<10)month = 0+""+month;
					if(check_latest_start_date_time>check_finish_date_time){
						//alert("* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE_EXCEED_FINISH_DATE;?>\n");
						document.new_subscription.subscription_latest_start_date.value=document.new_subscription.subscription_start_date.value;
						old_latest_start_date = start_date;
						return false;
					}
					if(check_latest_start_date_time<check_start_date_time){
						//alert("* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_LATEST_START_DATE;?>\n");
						document.new_subscription.subscription_latest_start_date.value=document.new_subscription.subscription_start_date.value;
						old_latest_start_date = start_date;
						document.new_subscription.subscription_finish_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_finish_date = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_forward_period = forward_period;
					}
				}
				old_start_date = start_date;
			}
			 return true;
		}
	}

	function DateAdd(timeU,byMany,dateObj) {
		var millisecond=1;
		var second=millisecond*1000;
		var minute=second*60;
		var hour=minute*60;
		var day=hour*24;
		var year=day*365;
	
		var newDate;
		var dVal=dateObj.valueOf();
		switch(timeU) {
			case "ms": newDate=new Date(dVal+millisecond*byMany); break;
			case "s": newDate=new Date(dVal+second*byMany); break;
			case "mi": newDate=new Date(dVal+minute*byMany); break;
			case "h": newDate=new Date(dVal+hour*byMany); break;
			case "d": newDate=new Date(dVal+day*byMany); break;
			case "y": newDate=new Date(dVal+year*byMany); break;
		}
		return newDate;
	}
	function DateSub(timeU,byMany,dateObj) {
		var millisecond=1;
		var second=millisecond*1000;
		var minute=second*60;
		var hour=minute*60;
		var day=hour*24;
		var year=day*365;
	
		var newDate;
		var dVal=dateObj.valueOf();
		switch(timeU) {
			case "ms": newDate=new Date(dVal-millisecond*byMany); break;
			case "s": newDate=new Date(dVal-second*byMany); break;
			case "mi": newDate=new Date(dVal-minute*byMany); break;
			case "h": newDate=new Date(dVal-hour*byMany); break;
			case "d": newDate=new Date(dVal-day*byMany); break;
			case "y": newDate=new Date(dVal-year*byMany); break;
		}
		return newDate;
	}
	</script>
	<?php 	$form_action = ($HTTP_GET_VARS['suID']) ? 'update_subscription' : 'insert_subscription';

		echo tep_draw_form('new_subscription', FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath  . '&suID=' . $HTTP_GET_VARS['suID'] . '&action='. $form_action, 'post', 'onSubmit="return ValidateForm();" enctype="multipart/form-data"'); ?>
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td><table border="10" width="100%" cellspacing="0" cellpadding="0">
			  <!--<tr>
				<td class="pageHeading"><?php //echo TEXT_NEW_SUBSCRIPTION; ?></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>
		  <?php 
		  
		  
		  tep_content_title_top("Categories"); 
		  ?>
		  
		  <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_SUBSCRIPTION_CATEGORIES; ?></td>
						<td class="main" width="200"><?php echo tep_draw_mselect_menu('subscription_categories_ids[]', $subscription_categories_array, $subscription_categories_array_selected, 'size=10 id=subscription_categories_ids style="width:400"'); ?></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" width="100%">
				
					<tr>
						<td>
						<table border=0 cellpadding="0" cellspacing="0">
							<tr>
								<td class="main" width="150" valign="top"><?php echo TEXT_SUBSCRIPTION_STATUS; ?></td>
								<td class="main" width="200" valign="top"><?php echo tep_draw_pull_down_menu('subscription_status', $status_array, $suInfo->subscription_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_SUBSCRIPTION_DATE_AVAILABLE; ?><br><small>(<?php echo $date_format;?>)</small></td>
								<td class="main" width="200" valign="top"><?php echo tep_draw_input_field("subscription_date_available",(tep_not_null($suInfo->subscription_date_available)?format_date($suInfo->subscription_date_available):format_date($current_date)),"size=10",false,'text',false);?>
								<a href="javascript:show_calendar('new_subscription.subscription_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>
					 <?php tep_content_title_bottom(); ?>
					<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>
												<td class="main" width="150"><?php if ($i == 0) echo TEXT_SUBSCRIPTION_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('subscription_name[' . $languages[$i]['id'] . ']', (isset($subscription_name[$languages[$i]['id']]) ? $subscription_name[$languages[$i]['id']] : tep_get_subscription_name($suInfo->subscription_id, $languages[$i]['id'])),' size=40 maxlength:64'); ?></td>
											</tr>
									<?php
									}
									?>
								</table>
								</td>
							</tr>
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr>
										<td class="main" valign="top" width="150"><?php if ($i == 0) echo TEXT_SUBSCRIPTION_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('subscription_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24', (isset($subscription_description[$languages[$i]['id']]) ? $subscription_description[$languages[$i]['id']] : tep_get_subscription_description($suInfo->subscription_id, $languages[$i]['id'])),'id="subscription_description[' . $languages[$i]['id'] . ']"'); ?></td>
											</tr>
										</table>
										</td>
									</tr>
								<?php
								}
								?>									

							</table>
							</td>
						</tr>
						<tr>
							<td width="100%">
							<table border="0" cellpadding="0" cellspacing="0" >
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr>
										<td class="main" width="120"><?php if ($i == 0) echo TEXT_SUBSCRIPTION_URL . '<br><small>' . TEXT_SUBSCRIPTION_URL_WITHOUT_HTTP . '</small>'; ?></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('subscription_url[' . $languages[$i]['id'] . ']', (isset($subscription_url[$languages[$i]['id']]) ? $subscription_url[$languages[$i]['id']] : tep_get_subscription_url($suInfo->subscription_id, $languages[$i]['id'])),'size=40 maxlength:255'); 
											 echo '&nbsp;&nbsp;'.TEXT_SUBSCRIPTION_IMAGE .'&nbsp;&nbsp;'. tep_draw_file_field('subscription_image') . '<br>' . tep_draw_separator('pixel_trans.gif',340,10) . $suInfo->subscription_image . tep_draw_hidden_field('subscription_previous_image', $suInfo->subscription_image); ?></td>
									</tr>
								<?php
								}
								?>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>		  
							<!--<tr>
									<td class="main" width="150"><?php echo TEXT_SUBSCRIPTION_IMAGE; ?></td>
									<td class="main"><?php echo tep_draw_file_field('subscription_image') . '<br>' . $suInfo->subscription_image . tep_draw_hidden_field('subscription_previous_image', $suInfo->subscription_image); ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>-->
								<tr>
									<td class="main" width="120"><?php echo TEXT_SUBSCRIPTION_TYPE; ?></td>
									<td>
										<?php $type_array=array(
																array('id'=>'B','text'=>TEXT_SUBSCRIPTION_BASIC),
																//array('id'=>'D','text'=>TEXT_SUBSCRIPTION_DIGITAL),
																array('id'=>'C','text'=>TEXT_SUBSCRIPTION_CASUAL),
																array('id'=>'S','text'=>TEXT_SUBSCRIPTION_SEASONAL)		
										);?>
										<table border="0" cellspacing="0" cellpadding="0" width="70%">
											<tr>
												<td  class="main"><?php echo tep_draw_pull_down_menu('subscription_type',$type_array,$suInfo->subscription_type,'onchange=javascript:do_subscription_type()');?></td>
												<td class="main" align="left">
													<div id="box_deliveries" style="display:none">
														<?php echo '&nbsp;&nbsp;'.tep_draw_input_field('txt_deliveries',$suInfo->deliveries,'size=5 maxlength:6');
															  echo ' ' . tep_draw_input_field('txt_deliveries_name',$suInfo->deliveries_name,'size=9 maxlength:20');
														 ?>
													</div>
													
												</td>
												<td class="main" align="left" width="120">
													<div id="box_perday" style="display:none">
														<?php echo '&nbsp;'.TEXT_PER .'  '. tep_draw_input_field('txt_perday',$suInfo->deliveries_perday,'size=5 maxlength:6') .'  '. TEXT_DAY;?>
													</div>
												</td>												
											</tr>	
											
											<script language="javascript">do_subscription_type();</script>			
										</table>	
									</td>									
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td valign="top" class="main">
										<?php echo TEXT_SUBSCRIPTION_DATE_TYPE;?>
									</td>
									<td class="main" valign="top">
										<?php 
											$sub_date_type = '';
											if($suInfo->subscription_date_type == "")$sub_date_type = 'F';
											else $sub_date_type = $suInfo->subscription_date_type;
											echo tep_draw_radio_field("subscription_date_type",'F',($sub_date_type=='F')?true:false,'',' onchange=javascript:do_subscription_date_type() ') . TEXT_FIXED. '&nbsp;';
											echo tep_draw_radio_field("subscription_date_type",'L',($sub_date_type=='L')?true:false,'',' onchange=javascript:do_subscription_date_type() ') . TEXT_FLEXIBLE . '&nbsp;';
											echo tep_draw_radio_field('subscription_date_type','P',($sub_date_type=='P')?true:false,'',' onchange=javascript:do_subscription_date_type() ') . TEXT_PREDEFINED. tep_draw_separator('pixel_trans.gif',70,10);
											echo TEXT_SUBSCRIPTION_PERIOD . '&nbsp;&nbsp;' . tep_draw_input_field('subscription_period',(tep_not_null($suInfo->subscription_period)?$suInfo->subscription_period:'1'),' size=5 id="subscription_period" onblur="check_input(true)"') . "&nbsp;" . TEXT_DAY;
										?>
									</td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
							</table>
							<table border="0" cellpadding="0" cellspacing="0" >
								<tr>
									<?php
										echo '<input type="hidden" name="currend_date" id="currend_date" value="' . date(EVENTS_DATE_FORMAT)  . '">';
									?>
									<td class="main" width="80" valign="top" align="left">
										<?php echo TEXT_SUBSCRIPTION_START_DATE;?>
									</td>
									<td class="main" width="50" valign="top" align="left">
									<?php
										 echo tep_draw_input_field("subscription_start_date",(tep_not_null($suInfo->subscription_start_date)?format_date($suInfo->subscription_start_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";
									?>
									</td>
									<td class="main" width="30" valign="top" align="left">
									<a href="javascript:show_calendar('new_subscription.subscription_start_date',null,null,'<?php echo $date_format;?>');"
									   onmouseover="window.status='Date Picker';return true;"
									   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_start_date_icon" name="subscription_start_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
									</a>
									</td>
									<td class="main" width="80" valign="top" align="left">
										<?php echo TEXT_SUBSCRIPTION_FINISH_DATE;  ?>
									</td>
									<td class="main" width="50" valign="top" align="left">
									<?php 
										echo tep_draw_input_field("subscription_finish_date",(tep_not_null($suInfo->subscription_finish_date)?format_date($suInfo->subscription_finish_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";
									?>
									</td>
									<td width="30" valign="top" align="left">
										<a href="javascript:show_calendar('new_subscription.subscription_finish_date',null,null,'<?php echo $date_format;?>');"
									   onmouseover="window.status='Date Picker';return true;"
									   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_begins_date_icon" name="subscription_begins_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
									</a>
									</td>
										
									<td id="fixed_date" style="display:none" >
										<table border="0"  cellpadding="0" cellspacing="0" width="100%">
											<tr>
											   <td class="main" width="200" valign="top" align="left">
													<?php  echo TEXT_SUBSCRIPTION_LATEST_START_DATE; ?>
												</td>
												<td width="50" valign="top" align="left">
													<?php echo tep_draw_input_field("subscription_latest_start_date",(tep_not_null($suInfo->subscription_latest_start_date)?format_date($suInfo->subscription_latest_start_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";?>
												</td>
												<td valign="top" align="left">								
													<a href="javascript:show_calendar('new_subscription.subscription_latest_start_date',null,null,'<?php echo $date_format;?>');"
													   onmouseover="window.status='Date Picker';return true;"
													   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_begins_date_icon" name="subscription_begins_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
													</a>
												</td>
											</tr></table>
										</td>	
								</tr>
								<!--<tr>
									<td class="main" width="180" valign="top" align="left"><?php echo TEXT_SUBSCRIPTION_FINISH_DATE;?></td>
									<td class="main" width="50" valign="top" align="left">
									<?php 
										echo tep_draw_input_field("subscription_finish_date",(tep_not_null($suInfo->subscription_finish_date)?format_date($suInfo->subscription_finish_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";
									?>
									</td>
									<td class="main" width="50" valign="top" align="left">
									<a href="javascript:show_calendar('new_subscription.subscription_finish_date',null,null,'<?php echo $date_format;?>');"
									   onmouseover="window.status='Date Picker';return true;"
									   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_begins_date_icon" name="subscription_begins_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
									</a>
									</td>
								</tr>
								<tr id="fixed_date" style="display:none">
									<td class="main" width="180" valign="top" align="left"><?php echo TEXT_SUBSCRIPTION_LATEST_START_DATE;?></td>
									<td class="main" width="50" valign="top" align="left">
									<?php 
										echo tep_draw_input_field("subscription_latest_start_date",(tep_not_null($suInfo->subscription_latest_start_date)?format_date($suInfo->subscription_latest_start_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";
									?>
									</td>
									<td class="main" width="50" valign="top" align="left" colspan="3">
									<a href="javascript:show_calendar('new_subscription.subscription_latest_start_date',null,null,'<?php echo $date_format;?>');"
									   onmouseover="window.status='Date Picker';return true;"
									   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_begins_date_icon" name="subscription_begins_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
									</a>
									</td>
								</tr>-->
								<!--<tr>
									<td class="main" width="180" valign="top">
										<?php echo TEXT_SUBSCRIPTION_PERIOD;?>
									</td>
									<td class="main" width="50" valign="top" colspan="2">
										<?php
											echo tep_draw_input_field('subscription_period',(tep_not_null($suInfo->subscription_period)?$suInfo->subscription_period:'1'),' size=5 id="subscription_period" onblur="check_input(true)"') . "&nbsp;" . TEXT_DAY;
										?>
									</td>
								</tr>-->
							</table>
							<script language="javascript" type="text/javascript">
								do_subscription_date_type();
							</script>
							</td>
						</tr>
					</table>
					</td>
				</tr>
					<?php tep_content_title_bottom(); ?>
				
 
					<?php tep_content_title_top("Fees"); ?>
					<tr>
						<td>
						<table border=0 cellpadding="4" cellspacing="0" width="80%">
							<tr>
								<td class="main" width="150"><?php echo TEXT_SUBSCRIPTION_TAX_CLASS .tep_draw_separator('pixel_trans.gif',30,10).tep_draw_pull_down_menu('subscription_tax_class_id', $tax_class_array, $suInfo->subscription_tax_class_id, 'onchange="updateGross()"') ; ?></td>
								<td class="main" width="150"><?php 
								$price=$suInfo->subscription_costs;
			           	 		if(strpos($price,".") && substr($price,strpos($price,"."))<=0) $price=(int)$price;
								echo TEXT_SUBSCRIPTION_FEES_NET_INFO .tep_draw_separator('pixel_trans.gif',30,10). tep_draw_input_field('subscription_costs_net',$price , 'onKeyUp="updateGross()"') ; ?></td>
<!--								<td class="main" width="50" align="left"><?php echo tep_draw_input_field('subscription_costs_net', $suInfo->subscription_costs, 'onKeyUp="updateGross()"'); ?></td>
-->								<td class="main" width="150"><?php echo TEXT_SUBSCRIPTION_FEES_GROSS_INFO .tep_draw_separator('pixel_trans.gif',30,10). tep_draw_input_field('subscription_costs_gross', $suInfo->subscription_costs, 'OnKeyUp="updateNet()"'); ?></td>
<!--								<td class="main" width="50"><?php echo tep_draw_input_field('subscription_costs_gross', $suInfo->subscription_costs, 'OnKeyUp="updateNet()"'); ?></td>
-->							</tr>
							<!--<tr>
								<td class="main"><?php echo TEXT_SUBSCRIPTION_FEES_NET_INFO; ?></td>
								<td class="main"><?php echo tep_draw_input_field('subscription_costs_net', $suInfo->subscription_costs, 'onKeyUp="updateGross()"'); ?></td>
							</tr>
	
							<tr>
								<td class="main"><?php echo TEXT_SUBSCRIPTION_FEES_GROSS_INFO; ?></td>
								<td class="main"><?php echo tep_draw_input_field('subscription_costs_gross', $suInfo->subscription_costs, 'OnKeyUp="updateNet()"'); ?></td>
							</tr>-->
							<tr>
							<td align=left class="tableHeading"><?php echo tep_draw_checkbox_field('pack_slip',true,($suInfo->subscription_packing_slip)?true:false ,'','onclick=javascript:(this.checked)?document.getElementById(\'slip_mess\').style.display="":document.getElementById(\'slip_mess\').style.display="none"').' '.TITLE_GROUP_PACKING_SLIP;?></td>
							</tr>
						</table>
						</td>
					</tr>	
					<?php tep_content_title_bottom(); ?> 
				<script language="javascript"><!--
			        updateGross();
			//--></script>	  
				
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
				</tr>
				<tr>
					<td>
					<table border=0 cellpadding="0" cellspacing="0" width="50%" id="slip_mess" <?php echo ($suInfo->subscription_packing_slip=='')?'style="display:none"':'';?>>
						<tr>
							<td class="main" valign="top">
								<?php 
										echo tep_draw_textarea_field('message_text','soft','50','10',$suInfo->subscription_packing_slip,'style="height:100"');
								?>
							</td>
							<td valign="top" align=center class="main">
								<?php 
									   echo tep_draw_pull_down_menu('merge_fields',$merge_fields,'','style="height:100" size=5 ondblClick="AddField()"');

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

		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		
		<?php tep_content_title_top("Conditions"); ?>
		<tr>
			<td>
			<table border="0" cellspacing="0" cellpadding="4"  width="100%">
				
				<tr>
					<td class="main" width="140"><?php echo TEXT_SUBSCRIPTION_GROUP;?></td>
					<td class="main"><?php echo tep_draw_pull_down_menu("subscription_group",$subscription_groups_array,$suInfo->subscription_group);?></td>
				</tr>
				<tr>
					<td class="main" width="140" valign="top"><?php echo TEXT_SUBSCRIPTION_CONDITIONS;?></td>
					<td class="main"><?php echo tep_draw_textarea_field("subscription_conditions",'wrap',50,5,$suInfo->subscription_conditions);?></td>
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_SUBSCRIPTION_PENDING_PERIOD;?></td>
					<td  class="main"><?php echo tep_draw_input_field("subscription_pending_period",$suInfo->subscription_pending_period,'size=10 maxlength:6');
							  echo tep_draw_separator('pixel_trans.gif',130,10) . TEXT_SUBSCRIPTION_RENEWAL_START .'&nbsp;&nbsp;' ;	
							  echo tep_draw_separator('pixel_trans.gif',20,10).tep_draw_input_field("subscription_renewal_start",$suInfo->subscription_renewal_start,'size=5 maxlength:6').'&nbsp;' . TEXT_SUBSCRIPTION_DAYS;?></td>
				</tr>
				<!--<tr>
					<td class="main" width="140"><?php echo TEXT_SUBSCRIPTION_RENEWAL_START; ?></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_input_field("subscription_renewal_start",$suInfo->subscription_renewal_start,'size=5 maxlength:6').'&nbsp;' . TEXT_SUBSCRIPTION_DAYS;?></td>
				</tr>-->
				<!--<tr>
					<td class="main" width="140"><?php echo TEXT_SUBSCRIPTION_RENEWAL_END;?></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_input_field("subscription_renewal_end",$suInfo->subscription_renewal_end,'size=5 maxlength:6') . '&nbsp;' . TEXT_SUBSCRIPTION_DAYS;?></td>
				</tr>
				<tr>
					<td class="main" width="140"><?php echo EMARKETING_RENEWAL;?></td>
					<td class="main" width="100"><?php echo tep_draw_radio_field("emarket_renew_continue",'1',($suInfo->emarketing_on_renewal=='C')?true:false) . TEXT_CONTINUE. '&nbsp;' . tep_draw_radio_field("emarket_renew_continue",'0',($suInfo->emarketing_on_renewal=='S')?true:false) . TEXT_STOP;?></td>
				</tr>-->
				<tr>
					<td class="main" width="140"><?php echo TEXT_FREE_TRIAL;?></td>
					<td class="main" width="200" valign="top">
					<?php 
						echo tep_draw_checkbox_field('subscription_free_trial','Y',($suInfo->subscription_free_trial=='Y'?true:false)) . '&nbsp;&nbsp;';
						echo TEXT_FREE_DAYS . '&nbsp;&nbsp;' . tep_draw_input_field("subscription_free_days",$suInfo->subscription_free_days,'size=7 maxlength:6');
						echo tep_draw_separator('pixel_trans.gif',80,10) . TEXT_SUBSCRIPTION_RENEWAL_END . '&nbsp;&nbsp;';
						echo tep_draw_separator('pixel_trans.gif',28,10).tep_draw_input_field("subscription_renewal_end",$suInfo->subscription_renewal_end,'size=5 maxlength:6') . '&nbsp;' . TEXT_SUBSCRIPTION_DAYS;
					?>
					</td>
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_WALLET_PAYMENT ?></td>
					<td class="main" width="150" valign="top">
					<?php echo tep_draw_checkbox_field('wallet_payment','Y',($suInfo->wallet_payment=='Y'?true:false),'','onclick="set_action(1);"');
						  echo  tep_draw_separator('pixel_trans.gif',180,10) . EMARKETING_RENEWAL . '&nbsp;&nbsp;';
						  echo  tep_draw_radio_field("emarket_renew_continue",'1',($suInfo->emarketing_on_renewal=='C')?true:false) . TEXT_CONTINUE. '&nbsp;' . tep_draw_radio_field("emarket_renew_continue",'0',($suInfo->emarketing_on_renewal=='S')?true:false) . TEXT_STOP;
					 ?>
					</td>
					
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_PERIODIC_PAYMENT;?></td>
					<td class="main"valign="top">
					<?php 
						echo tep_draw_checkbox_field('periodic_payment','Y',($suInfo->periodic_payment=='Y'?true:false),'','onclick="set_action(2);"') . '&nbsp;&nbsp;';
						echo TEXT_PERIODIC . '&nbsp;&nbsp;' . tep_draw_input_field("periodic_days",$suInfo->periodic_days,'size=7 maxlength:6' .'  '.($suInfo->periodic_payment=='Y'?'enabled':'disabled')) . '&nbsp;&nbsp;';
						echo TEXT_DAYS . '&nbsp;&nbsp;';
					    echo tep_draw_pull_down_menu('periodic_type',$wallet_periodic_fields,$suInfo->periodic_type,($suInfo->periodic_payment=='Y'?'enabled':'disabled'));
					?>
					
					</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('subscription_date_added', (($suInfo->date_added) ? $suInfo->date_added : getServerDate())) . tep_image_submit('button_save.gif', IMAGE_SAVE_SUBSCRIPTION) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'top=1&mPath=5') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; 
				?>
			</td>
		</tr>
	</table>
	</td>
</tr>
</table>
	<?php
	/* if (HTML_AREA_WYSIWYG_DISABLE == 'Disable') {} else { ?>
            <?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
          		<script language="javascript">initEditor('subscription_description[<?php echo $languages[$i]['id']; ?>]');</script>
     		<?php } }>*/ ?>
	<?php 
	} elseif ($HTTP_GET_VARS['action'] == 'new_subscription_category_preview') {
		if ($HTTP_POST_VARS) {
			$sucInfo = new objectInfo($HTTP_POST_VARS);
			$subscription_categories_name = $HTTP_POST_VARS['subscription_categories_name'];
			$subscription_categories_heading_title = $HTTP_POST_VARS['subscription_categories_heading_title'];
			$subscription_categories_description = $HTTP_POST_VARS['subscription_categories_description'];
			// copy image only if modified
			$subscription_categories_image = new upload('subscription_categories_image');
			$subscription_categories_image->set_destination(DIR_FS_CATALOG_IMAGES);
			if ($subscription_categories_image->parse() && $subscription_categories_image->save()) {
				$subscription_categories_image_name = $subscription_categories_image->filename;
			} else {
				$subscription_categories_image_name = $HTTP_POST_VARS['subscription_categories_previous_image'];
			}
	    } else {
			$subscription_category_query = tep_db_query("SELECT suc.subscription_categories_id, sucd.language_id, sucd.subscription_categories_name, sucd.subscription_categories_heading_title, sucd.subscription_categories_description, suc.subscription_categories_image, suc.sort_order, suc.date_added, suc.last_modified from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id = sucd.subscription_categories_id and suc.subscription_categories_id = '" . (int)$HTTP_GET_VARS['sucID'] . "' and sucd.language_id='" . $languages_id . "'");
			$subscription_category = tep_db_fetch_array($subscription_category_query);
			
			$sucInfo = new objectInfo($subscription_category);
			$subscription_categories_image_name = $sucInfo->subscription_categories_image;
		}

		$form_action = ($HTTP_GET_VARS['sucID']) ? 'update_subscription_category' : 'insert_subscription_category';
		
		echo tep_draw_form($form_action, FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $HTTP_GET_VARS['sucID'] . '&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') { 
				$sucInfo->subscription_categories_name = tep_get_subscription_category_name($sucInfo->subscription_categories_id, $languages[$i]['id']);
				$sucInfo->subscription_categories_heading_title = tep_get_subscription_category_title($sucInfo->subscription_categories_id, $languages[$i]['id']);
				$sucInfo->subscription_categories_description = tep_get_subscription_category_description($sucInfo->subscription_categories_id, $languages[$i]['id']);
			} else {
				$sucInfo->subscription_categories_name = tep_db_prepare_input($subscription_categories_name[$languages[$i]['id']]);
				$sucInfo->subscription_categories_heading_title = tep_db_prepare_input($subscription_categories_heading_title[$languages[$i]['id']]);
				$sucInfo->subscription_categories_description = tep_db_prepare_input($subscription_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;' . $sucInfo->subscription_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 . $subscription_categories_image_name, $sucInfo->subscription_categories_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $sucInfo->subscription_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_SUBSCRIPTION_CATEGORIES;
				$back_url_params = 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_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('subscription_categories_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subscription_categories_name[$languages[$i]['id']])));
				echo tep_draw_hidden_field('subscription_categories_heading_title[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subscription_categories_heading_title[$languages[$i]['id']])));
				echo tep_draw_hidden_field('subscription_categories_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subscription_categories_description[$languages[$i]['id']])));
			  }
			  echo tep_draw_hidden_field('X_subscription_categories_image', stripslashes($subscription_categories_image_name));
			  echo tep_draw_hidden_field('subscription_categories_image', stripslashes($subscription_categories_image_name));
		
			  echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';
		
			  if ($HTTP_GET_VARS['sucID']) {
				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_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $HTTP_GET_VARS['sucID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
		?></td>
      	</form></tr>
		<?php
    		}
		  } else if ($action=="new_subscription_preview") {
  
		   if (tep_not_null($HTTP_POST_VARS)) {
			  $suInfo = new objectInfo($HTTP_POST_VARS);
			  $subscription_name = $HTTP_POST_VARS['subscription_name'];
			  $subscription_description = $HTTP_POST_VARS['subscription_description'];
			  $subscription_url = $HTTP_POST_VARS['subscription_url'];
			} else {
			  $subscription_query = tep_db_query("SELECT su.subscription_id,su.emarketing_on_renewal, sud.language_id, sud.subscription_name, sud.subscription_description, sud.subscription_url, su.subscription_image, su.subscription_date_added, su.subscription_last_modified, su.subscription_date_available, su.subscription_status,su.subscription_costs, " . 
										  "su.subscription_tax_class_id,su.subscription_type from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . 
						  				  " sud where su.subscription_id = sud.subscription_id and su.subscription_id = '" . (int)$HTTP_GET_VARS['suID'] . "' and language_id='" . $languages_id . "'");
			  $subscription = tep_db_fetch_array($subscription_query);
				$suInfo = new objectInfo($subscription);
		
			  $subscription_image_name = $suInfo->subscription_image;
			}
		
			$form_action = (isset($HTTP_GET_VARS['suID'])) ? 'update_subscription' : 'insert_subscription';

			echo tep_draw_form($form_action, FILENAME_SUBSCRIPTION_CATEGORIES, '&sucPath=' . $sucPath . (isset($HTTP_GET_VARS['suID']) ? '&suID=' . $HTTP_GET_VARS['suID'] : '') . '&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')) {
			  } else {
				$suInfo->subscription_name = tep_db_prepare_input($subscription_name[$languages[$i]['name']]);
				$suInfo->subscription_description = tep_db_prepare_input($subscription_description[$languages[$i]['id']]);
				$suInfo->subscription_url = tep_db_prepare_input($subscription_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;' . $suInfo->subscription_name; ?></td>
					<td class="pageHeading" align="right"><?php echo $currencies->format($suInfo->subscription_costs); ?></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 . $subscription_image_name, $suInfo->subscription_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $suInfo->subscription_description; ?></td>
		</tr>
		<?php
			  if ($suInfo->subscription_url) {
		?>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr>
			<td class="main"><?php echo sprintf(TEXT_SUBSCRIPTION_MORE_INFORMATION, $suInfo->subscription_url); ?></td>
		</tr>
		<?php
			  }
		?>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<?php
			  if ($suInfo->subscription_date_available > getServerDate()) {
		?>
		<tr>
			<td align="center" class="smallText"><?php echo sprintf(TEXT_SUBSCRIPTION_DATE_AVAILABLE_PRE,tep_date_long($suInfo->subscription_date_available)); ?></td>
		</tr>
		<?php
			  } else {
		?>
			<tr>
			<td align="center" class="smallText"><?php echo sprintf(TEXT_SUBSCRIPTION_DATE_ADDED_PRE, tep_date_long($suInfo->subscription_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_SUBSCRIPTION_CATEGORIES;
					$back_url_params = 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_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
			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('subscription_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subsciption_name[$languages[$i]['id']])));
					echo tep_draw_hidden_field('subscription_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subscription_description[$languages[$i]['id']])));
					echo tep_draw_hidden_field('subscription_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subscription_url[$languages[$i]['id']])));
				  }
			} // false

			  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)));
				}
			  }
			  echo tep_draw_hidden_field('subscription_image', stripslashes($subscription_image_name));
		
			  echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';
		
			  if (isset($HTTP_GET_VARS['suID'])) {
				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_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . (isset($HTTP_GET_VARS['suID']) ? '&suID=' . $HTTP_GET_VARS['suID'] : '')) . '">' . 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 tep_output_rev_generated_subscription_category_path($current_subscription_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_SUBSCRIPTION_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_SUBSCRIPTION_CATEGORIES, '', 'get');
			echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('sucPath', tep_get_subscription_category_tree(), $current_subscription_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_SUBSCRIPTION_CATEGORIES; ?></td>
						<td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_SUBSCRIPTION_STATUS; ?></td>
						<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_SUBSCRIPTION_ACTION; ?>&nbsp;</td>
					  </tr>
				<?php
					$subscription_categories_count = 0;
					$rows = 0;
					if (isset($HTTP_GET_VARS['search'])) {
					  $search = tep_db_prepare_input($HTTP_GET_VARS['search']);
				
					  $subscription_categories_query = tep_db_query("SELECT suc.subscription_categories_id, sucd.subscription_categories_name, suc.subscription_categories_image, suc.parent_id, suc.sort_order, suc.date_added, suc.last_modified from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id = sucd.subscription_categories_id and sucd.language_id = '" . (int)$languages_id . "' and sucd.subscription_categories_name like '%" . tep_db_input($search) . "%' order by suc.sort_order, sucd.subscription_categories_name");
					} else {
					  $subscription_categories_query = tep_db_query("SELECT suc.subscription_categories_id, sucd.subscription_categories_name, suc.subscription_categories_image, suc.parent_id, suc.sort_order, suc.date_added, suc.last_modified from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id = sucd.subscription_categories_id and suc.parent_id = '" . (int)$current_subscription_category_id . "' and sucd.language_id = '" . (int)$languages_id . "' order by suc.sort_order, sucd.subscription_categories_name");
					}
					while ($subscription_categories = tep_db_fetch_array($subscription_categories_query)) {
					  $subscription_categories_count++;
					  $rows++;
					  // Get parent_id for subcategories if search
					  if (isset($HTTP_GET_VARS['search'])) $sucPath=$subscription_categories['parent_id'];

					  if ((!isset($HTTP_GET_VARS['sucID']) && !isset($HTTP_GET_VARS['suID']) || (isset($HTTP_GET_VARS['sucID']) && ($HTTP_GET_VARS['sucID'] == $subscription_categories['subscription_categories_id']))) && !isset($sucInfo) && (substr($action, 0, 3) != 'new')) {
						$subscription_category_childs = array('childs_count' => tep_childs_in_subscription_category_count($subscription_categories['subscription_categories_id']));
						$subscription_category_subscription = array('subscriptions_count' => tep_subscription_in_subscription_category_count($subscription_categories['subscription_categories_id']));
						$sucInfo_array = array_merge($subscription_categories, $subscription_category_childs, $subscription_category_subscription);
						$sucInfo = new objectInfo($sucInfo_array);
					  }
 
					  if (isset($sucInfo) && is_object($sucInfo) && ($subscription_categories['subscription_categories_id'] == $sucInfo->subscription_categories_id) ) {
						echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $subscription_categories['subscription_categories_id'] . '&action=new_subscription_category_preview&read=only') . '\'">' . "\n";
					  } else {
						echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $subscription_categories['subscription_categories_id']) . '\'">' . "\n";
					  }
	  
						?>
					<td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, tep_get_subscription_path($subscription_categories['subscription_categories_id'])) . '">' . tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER) . '</a>&nbsp;<b>' . $subscription_categories['subscription_categories_name'] . '</b>'; ?></td>
					<td class="dataTableContent" align="center">&nbsp;</td>
					<td class="dataTableContent" align="right"><?php if (isset($sucInfo) && is_object($sucInfo) && ($subscription_categories['subscription_categories_id'] == $sucInfo->subscription_categories_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $subscription_categories['subscription_categories_id'] . '&action=new_subscription_category_preview&read=only') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
				  </tr>
				<?php
					}
					$subscriptions_count=0;
					if (isset($HTTP_GET_VARS['search'])) {
						$subscription_query = tep_db_query("SELECT su.subscription_id, sud.subscription_name, su.subscription_image, su.subscription_date_added, su.subscription_last_modified, su.subscription_date_available, su.subscription_status, su2c.subscription_categories_id from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " su2c, " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud  where su.subscription_id = su2c.subscription_id and su.subscription_id = sud.subscription_id and sud.language_id = '" . (int)$languages_id . "' and sud.subscription_name like '%" . tep_db_input($search) . "%' order by sud.subscription_name");
					} else {
						$subscription_query = tep_db_query("SELECT su.subscription_id, sud.subscription_name, su.subscription_image, su.subscription_date_added, su.subscription_last_modified, su.subscription_date_available, su.subscription_status from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " su2c, " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where su.subscription_id = su2c.subscription_id and su.subscription_id=sud.subscription_id and sud.language_id = '" . (int)$languages_id . "' and su2c.subscription_categories_id = '" . (int)$current_subscription_category_id . "' order by sud.subscription_name");
					}
					while( $subscription=tep_db_fetch_array($subscription_query)){
						$rows++;
						$subscriptions_count++;
			
						if ( (!isset($HTTP_GET_VARS['suID']) && !isset($HTTP_GET_VARS['sucID']) || (isset($HTTP_GET_VARS['suID']) && ($HTTP_GET_VARS['suID'] == $subscription['subscription_id']))) && !isset($suInfo) && !isset($sucInfo) && (substr($action, 0, 3) != 'new')){
							$suInfo=new objectInfo($subscription);
						}

						
					  if (isset($suInfo) && is_object($suInfo) && ($subscription['subscription_id'] == $suInfo->subscription_id)) {
						echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $subscription['subscription_id'] . '&action=new_subscription_preview&read=only') . '\'">' . "\n";
					  } else {
						echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $subscription['subscription_id']) . '\'">' . "\n";
					  }
				?>
									<td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $subscription['subscription_id']) . '&action=new_subscription_preview&read=only' . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;' . $subscription["subscription_name"]; ?></td>
					                <td class="dataTableContent" align="left">
										<?php
											  if ($subscription['subscription_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_SUBSCRIPTION_CATEGORIES, 'action=setflag&flag=0&sucPath=' . $sucPath . '&suID=' . $subscription['subscription_id']) . '">' . 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_SUBSCRIPTION_CATEGORIES, 'action=setflag&flag=1&sucPath=' . $sucPath . '&suID=' . $subscription['subscription_id']) . '">' . 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 ($subscription['subscription_status']==2){
													echo '&nbsp;' . tep_image(DIR_WS_ICONS . 'warning.gif',IMAGE_HIDE_START_SUBSCRIPTION);
												} else if($subscription['subscription_status']>=3) {
													echo '&nbsp;' . tep_image(DIR_WS_ICONS . 'warning.gif',IMAGE_HIDE_END_SUBSCRIPTION);
												}
											  }
										?>
									</td>
					                <td class="dataTableContent" align="right"><?php if (isset($suInfo) && is_object($suInfo) && ($subscription['subscription_id'] == $suInfo->subscription_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $subscription['subscription_id']  . '&action=new_subscription_preview&read=only') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
								</tr>
							<?php
								}
									$sucPath_back = '';
									if (sizeof($sucPath_array) > 0) {
									  for ($i=0, $n=sizeof($sucPath_array)-1; $i<$n; $i++) {
										if (empty($sucPath_back)) {
										  $sucPath_back .= $sucPath_array[$i];
										} else {
										  $sucPath_back .= '_' . $sucPath_array[$i];
										}
									  }
									}
									
									$sucPath_back = (tep_not_null($sucPath_back)) ? 'sucPath=' . $sucPath_back . '&' : '';
							?>
								  <tr>
									<td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
									  <tr>
										<td class="smallText"><?php echo TEXT_SUBSCRIPTION_CATEGORIES . '&nbsp;' . $subscription_categories_count . '<br>' . TEXT_SUBSCRIPTIONS . '&nbsp;' . $subscriptions_count; ?></td>
										<td align="right" class="smallText"><?php if (sizeof($sucPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, $sucPath_back . 'sucID=' . $current_subscription_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_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&action=new_subscription_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&action=new_subscription') . '">' . tep_image_button('button_new_subscription.gif', IMAGE_NEW_SUBSCRIPTION) . '</a>'; ?>&nbsp;</td>
									  </tr>
									</table>
									</td>
								  </tr>
							</table>
							</td>
							<?php
								$heading = array();
								$contents = array();
								switch ($action) {
								  case 'new_subscription_category':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_SUBSCRIPTION_CATEGORY . '</b>');
										$contents = array('form' => tep_draw_form('new_subscription_category', FILENAME_SUBSCRIPTION_CATEGORIES, 'action=insert_subscription_category&sucPath=' . $sucPath, 'post', 'enctype="multipart/form-data"'));
										$contents[] = array('text' => TEXT_NEW_SUBSCRIPTION_CATEGORY_INTRO);
								
										$subscription_category_inputs_string = '';
										$languages = tep_get_languages();
										for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
										  $subscription_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('subscription_categories_name[' . $languages[$i]['id'] . ']');
										}
										$contents[] = array('text' => '<br>' . TEXT_SUBSCRIPTION_CATEGORIES_NAME . $subscription_category_inputs_string);
										$contents[] = array('text' => '<br>' . TEXT_SUBSCRIPTION_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('subscription_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_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
								  case 'edit_subscription_category':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_SUBSCRIPTION_CATEGORY . '</b>');
					
										$contents = array('form' => tep_draw_form('subscription_categories', FILENAME_SUBSCRIPTION_CATEGORIES, 'action=update_subscription_category&sucPath=' . $sucPath, 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('subscription_categories_id', $sucInfo->subscription_categories_id));
										$contents[] = array('text' => TEXT_EDIT_INTRO);
								
										$subscription_category_inputs_string = '';
										$languages = tep_get_languages();
										for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
										  $subscription_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('subscription_categories_name[' . $languages[$i]['id'] . ']', tep_get_subscription_category_name($sucInfo->subscription_categories_id, $languages[$i]['id']));
										}
								
										$contents[] = array('text' => '<br>' . TEXT_EDIT_SUBSCRIPTION_CATEGORIES_NAME . $subscription_category_inputs_string);
										$contents[] = array('text' => '<br>' . tep_image(DIR_WS_CATALOG_IMAGES . $sucInfo->subscription_categories_image, $sucInfo->categories_name) . '<br>' . DIR_WS_CATALOG_IMAGES . '<br><b>' . $sucInfo->subscription_categories_image . '</b>');
										$contents[] = array('text' => '<br>' . TEXT_EDIT_SUBSCRIPTION_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('subscription_categories_image'));
										$contents[] = array('text' => '<br>' . TEXT_EDIT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', $sucInfo->sort_order, 'size="2"'));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
								  case 'delete_subscription_category':
										$err_delete=false;
										if ($sucInfo->subscriptions_count>0 || $sucInfo->childs_count>0)
									   $err_delete=true;
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_SUBSCRIPTION_CATEGORY . '</b>');
										$contents = array('form' => tep_draw_form('subscription_categories', FILENAME_SUBSCRIPTION_CATEGORIES, 'action=delete_subscription_category_confirm&sucPath=' . $sucPath) . tep_draw_hidden_field('subscription_categories_id', $sucInfo->subscription_categories_id));
										$contents[] = array('text' => TEXT_DELETE_SUBSCRIPTION_CATEGORY_INTRO);
										$contents[] = array('text' => '<br><b>' . $sucInfo->subscription_categories_name . '</b>');
										if ($sucInfo->childs_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_CHILDS, $sucInfo->childs_count));
										if ($sucInfo->subscriptions_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_SUBSCRIPTION, $sucInfo->subscriptions_count));
										$contents[] = array('align' => 'center', 'text' => '<br>' . ($err_delete==false?tep_image_submit('button_delete.gif', IMAGE_DELETE):'') . ' <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
									case 'move_subscription_category':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_SUBSCRIPTION_CATEGORY . '</b>');
					
										$contents = array('form' => tep_draw_form('subscription_categories', FILENAME_SUBSCRIPTION_CATEGORIES, 'action=move_subscription_category_confirm&sucPath=' . $sucPath) . tep_draw_hidden_field('subscription_categories_id', $sucInfo->subscription_categories_id));
										$contents[] = array('text' => sprintf(TEXT_MOVE_SUBSCRIPTION_CATEGORIES_INTRO, $sucInfo->subscription_categories_name));
										$contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $sucInfo->subscription_categories_name) . '<br>' . tep_draw_pull_down_menu('move_to_subscription_category_id', tep_get_subscription_category_tree(), $current_subscription_category_id));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
									case 'move_subscription':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_SUBSCRIPTION . '</b>');
								
										$contents = array('form' => tep_draw_form('subscription', FILENAME_SUBSCRIPTION_CATEGORIES, 'action=move_subscription_confirm&sucPath=' . $sucPath) . tep_draw_hidden_field('subscription_id', $suInfo->subscription_id));
										$contents[] = array('text' => sprintf(TEXT_MOVE_SUBSCRIPTION_INTRO, $sucInfo->subscription_name));
										$contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_SUBSCRIPTION_CATEGORIES . '<br><b>' . tep_output_generated_subscription_category_path($suInfo->subscription_id, 'subscription') . '</b>');
										$contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $sucInfo->subscription_name) . '<br>' . tep_draw_pull_down_menu('move_to_subscription_category_id', tep_get_subscription_category_tree(), $current_subscription_category_id));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
								  case 'delete_subscription':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_SUBSCRIPTION . '</b>');
								
										$contents = array('form' => tep_draw_form('subscription', FILENAME_SUBSCRIPTION_CATEGORIES, 'action=delete_subscription_confirm&sucPath=' . $sucPath) . tep_draw_hidden_field('subscription_id', $suInfo->subscription_id));
										$contents[] = array('text' => TEXT_DELETE_SUBSCRIPTION_INTRO);
										$contents[] = array('text' => '<br><b>' . $suInfo->subscription_name . '</b>');

										$subscription_categories_string = '';
										$subscription_categories = tep_generate_subscription_category_path($suInfo->subscription_id, 'subscription');
										for ($i = 0, $n = sizeof($subscription_categories); $i < $n; $i++) {
											$subscription_category_path = '';
											for ($j = 0, $k = sizeof($subscription_categories[$i]); $j < $k; $j++) {
												$subscription_category_path .= $subscription_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
											}
											$subscription_category_path = substr($subscription_category_path, 0, -16);
											$subscription_categories_string .= tep_draw_checkbox_field('subscription_categories[]', $subscription_categories[$i][sizeof($subscription_categories[$i])-1]['id'], true) . '&nbsp;' . $subscription_category_path . '<br>';
										}
										$subscription_categories_string = substr($subscription_categories_string, 0, -4);
								
										$contents[] = array('text' => '<br>' . $subscription_categories_string);
								        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_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_SUBSCRIPTION_CATEGORIES, 'action=copy_to_confirm&sucPath=' . $sucPath) . tep_draw_hidden_field('subscription_id', $suInfo->subscription_id));
										$contents[] = array('text' => TEXT_INFO_COPY_TO_INTRO);
										$contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_SUBSCRIPTION_CATEGORIES . '<br><b>' . tep_output_generated_subscription_category_path($suInfo->subscription_id, 'subscription') . '</b>');
										$contents[] = array('text' => '<br>' . TEXT_SUBSCRIPTION_CATEGORIES . '<br>' . tep_draw_pull_down_menu('subscription_categories_id', tep_get_subscription_category_tree(), $current_subscription_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_subscription','1')  . TEXT_COPY_MESSAGES);
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_copy.gif', IMAGE_COPY) . ' <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
									default:
										if ($rows>0) {
										  if (isset($sucInfo) && is_object($sucInfo)) { // category info box contents
											$heading[] = array('text' => '<b>' . $sucInfo->subscription_categories_name . '</b>');
											$contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_categories_id . '&action=edit_subscription_category') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_categories_id . '&action=delete_subscription_category') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) 
															 . '</a> <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&sucID=' . $sucInfo->subscription_categories_id . '&action=move_subscription_category') . '">' . tep_image_button('button_move.gif',IMAGE_MOVE) . '</a>');
											$contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . format_date($sucInfo->date_added));
											if (tep_not_null($sucInfo->last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . format_date($sucInfo->last_modified));
											$contents[] = array('text' => '<br>' . tep_info_image($sucInfo->subscription_categories_image, $sucInfo->subscription_categories_name, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT) . '<br>' . $sucInfo->subscription_categories_image);
											$contents[] = array('text' => '<br>' . TEXT_SUB_SUBSCRIPTION_CATEGORIES . ' ' . $sucInfo->childs_count . '<br>' . TEXT_SUBSCRIPTIONS . ' ' . $sucInfo->subscriptions_count);
									  } elseif (isset($suInfo) && is_object($suInfo)) { // subscription info box contents
											$heading[] = array('text' => '<b>' . tep_get_subscription_name($suInfo->subscription_id, $languages_id) . '</b>');
											$contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_id . '&action=new_subscription') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_id . '&action=delete_subscription') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a><br>' 
																. '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_id . '&action=move_subscription') . '">' . tep_image_button('button_move.gif', IMAGE_MOVE) . '</a> <a href="' . tep_href_link(FILENAME_SUBSCRIPTION_CATEGORIES, 'sucPath=' . $sucPath . '&suID=' . $suInfo->subscription_id . '&action=copy_to') . '">' . tep_image_button('button_copy_to.gif', IMAGE_COPY_TO) . '</a><p>');
											
											$contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_MESSAGES, 'subscriptionID=' . $suInfo->subscription_id) . '">' . tep_image_button('button_messages.gif', IMAGE_SUBSCRIPTION_MESSAGES) .'</a><br>');
											$contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . format_date($suInfo->subscription_date_added));
											if (tep_not_null($suInfo->subscription_last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . format_date($suInfo->subscription_last_modified));
											if (date('Y-m-d') < $suInfo->subscription_date_available) $contents[] = array('text' => TEXT_DATE_AVAILABLE . ' ' . format_date($suInfo->subscription_date_available));
											$contents[] = array('text' => '<br>' . tep_info_image($suInfo->subscription_image, $suInfo->subscription_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br>' . $suInfo->subscription_image);
										}
								  } else { // create subscription category/subscription info
									  $heading[] = array('text' => '<b>' . EMPTY_SUBSCRIPTION_CATEGORY . '</b>');
							
									  $contents[] = array('text' => TEXT_NO_CHILD_SUBSCRIPTION_CATEGORIES_OR_SUBSCRIPTION);
								  }
								  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_subscription_category;
		var error = "";
		if (frm.elements["subscription_categories_image"].value!="" && !check_mime_type(frm.elements["subscription_categories_image"],image_types)){
			error="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
		}
		if(error!=""){
			alert(error);
			return false;
		}
		return true;
	}
</script>
<!-- body_eof //-->
</td></tr></table>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
   var display_category=true;
   disp(document.getElementById('panel_Categories'));
   function disp(panel){
		for(i=0;i<category_list.length;i++){
			if(document.getElementById(category_list[i]) && document.getElementById(category_list[i])==panel){
				document.getElementById(category_list[i]).style.display="";
					document.getElementById(category_list[i]).style.display="";
			}else if(document.getElementById(category_list[i])){
				document.getElementById(category_list[i]).style.display="none";
			}
		}
	}
 </script>
 
	  
